File indexing completed on 2024-12-22 04:41:42
0001 /* 0002 * SPDX-FileCopyrightText: 2014 Albert Vaca Cintora <albertvaka@gmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0005 */ 0006 0007 package org.kde.kdeconnect; 0008 0009 import android.content.BroadcastReceiver; 0010 import android.content.Context; 0011 import android.content.Intent; 0012 import android.net.ConnectivityManager; 0013 import android.net.wifi.WifiManager; 0014 import android.util.Log; 0015 0016 public class KdeConnectBroadcastReceiver extends BroadcastReceiver { 0017 0018 public void onReceive(Context context, Intent intent) { 0019 0020 //Log.e("KdeConnect", "Broadcast event: "+intent.getAction()); 0021 0022 String action = intent.getAction(); 0023 0024 switch (action) { 0025 case Intent.ACTION_MY_PACKAGE_REPLACED: 0026 Log.i("KdeConnect", "MyUpdateReceiver"); 0027 BackgroundService.Start(context); 0028 break; 0029 case Intent.ACTION_BOOT_COMPLETED: 0030 Log.i("KdeConnect", "KdeConnectBroadcastReceiver"); 0031 try { 0032 BackgroundService.Start(context); 0033 } catch (IllegalStateException e) { // To catch ForegroundServiceStartNotAllowedException 0034 Log.w("BroadcastReceiver", "Couldn't start the foreground service."); 0035 e.printStackTrace(); 0036 } 0037 break; 0038 case WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION: 0039 case WifiManager.WIFI_STATE_CHANGED_ACTION: 0040 case ConnectivityManager.CONNECTIVITY_ACTION: 0041 Log.i("KdeConnect", "Connection state changed, trying to connect"); 0042 BackgroundService.ForceRefreshConnections(context); 0043 break; 0044 case Intent.ACTION_SCREEN_ON: 0045 try { 0046 BackgroundService.ForceRefreshConnections(context); 0047 } catch (IllegalStateException e) { // To catch ForegroundServiceStartNotAllowedException 0048 Log.w("BroadcastReceiver", "Couldn't start the foreground service."); 0049 e.printStackTrace(); 0050 } 0051 break; 0052 default: 0053 Log.i("BroadcastReceiver", "Ignoring broadcast event: " + intent.getAction()); 0054 break; 0055 } 0056 0057 } 0058 0059 0060 }