Loading service/src/com/android/server/bluetooth/BluetoothAirplaneModeListener.java +57 −46 Original line number Diff line number Diff line Loading @@ -32,16 +32,19 @@ import com.android.bluetooth.BluetoothStatsLog; import com.android.internal.annotations.VisibleForTesting; /** * The BluetoothAirplaneModeListener handles system airplane mode change callback and checks * whether we need to inform BluetoothManagerService on this change. * The BluetoothAirplaneModeListener handles system airplane mode change callback and checks whether * we need to inform BluetoothManagerService on this change. * * The information of airplane mode turns on would not be passed to the BluetoothManagerService * <p>The information of airplane mode turns on would not be passed to the BluetoothManagerService * when Bluetooth is on and Bluetooth is in one of the following situations: * 1. Bluetooth A2DP is connected. * 2. Bluetooth Hearing Aid profile is connected. * 3. Bluetooth LE Audio is connected * * <ul> * <li>Bluetooth A2DP is connected. * <li>Bluetooth Hearing Aid profile is connected. * <li>Bluetooth LE Audio is connected * </ul> */ public class BluetoothAirplaneModeListener { class BluetoothAirplaneModeListener { private static final String TAG = "BluetoothAirplaneModeListener"; @VisibleForTesting static final String TOAST_COUNT = "bluetooth_airplane_toast_count"; Loading Loading @@ -89,21 +92,27 @@ public class BluetoothAirplaneModeListener { @VisibleForTesting int mToastCount = 0; BluetoothAirplaneModeListener(BluetoothManagerService service, Looper looper, Context context, BluetoothAirplaneModeListener( BluetoothManagerService service, Looper looper, Context context, BluetoothNotificationManager notificationManager) { mBluetoothManager = service; mNotificationManager = notificationManager; mContext = context; mHandler = new BluetoothAirplaneModeHandler(looper); context.getContentResolver().registerContentObserver( Settings.Global.getUriFor(Settings.Global.AIRPLANE_MODE_ON), true, context.getContentResolver() .registerContentObserver( Settings.Global.getUriFor(Settings.Global.AIRPLANE_MODE_ON), true, mAirplaneModeObserver); } private final ContentObserver mAirplaneModeObserver = new ContentObserver(null) { private final ContentObserver mAirplaneModeObserver = new ContentObserver(null) { @Override public void onChange(boolean unused) { public void onChange(boolean selfChange) { // Post from system main thread to android_io thread. Message msg = mHandler.obtainMessage(MSG_AIRPLANE_MODE_CHANGED); mHandler.sendMessage(msg); Loading @@ -128,9 +137,7 @@ public class BluetoothAirplaneModeListener { } } /** * Call after boot complete */ /** Call after boot complete */ @VisibleForTesting void start(BluetoothModeChangeHelper helper) { Log.i(TAG, "start"); Loading Loading @@ -164,7 +171,8 @@ public class BluetoothAirplaneModeListener { // Airplane mode enabled when Bluetooth is being used for audio/headering aid. // Bluetooth is not disabled in such case, only state is changed to // BLUETOOTH_ON_AIRPLANE mode. mAirplaneHelper.setSettingsInt(Settings.Global.BLUETOOTH_ON, mAirplaneHelper.setSettingsInt( Settings.Global.BLUETOOTH_ON, BluetoothManagerService.BLUETOOTH_ON_AIRPLANE); if (!isApmEnhancementEnabled() || !isBluetoothToggledOnApm()) { if (shouldPopToast()) { Loading @@ -173,17 +181,20 @@ public class BluetoothAirplaneModeListener { } else { if (isWifiEnabledOnApm() && isFirstTimeNotification(APM_WIFI_BT_NOTIFICATION)) { try { sendApmNotification("bluetooth_and_wifi_stays_on_title", sendApmNotification( "bluetooth_and_wifi_stays_on_title", "bluetooth_and_wifi_stays_on_message", APM_WIFI_BT_NOTIFICATION); } catch (Exception e) { Log.e(TAG, Log.e( TAG, "APM enhancement BT and Wi-Fi stays on notification not shown"); } } else if (!isWifiEnabledOnApm() && isFirstTimeNotification( APM_BT_NOTIFICATION)) { } else if (!isWifiEnabledOnApm() && isFirstTimeNotification(APM_BT_NOTIFICATION)) { try { sendApmNotification("bluetooth_stays_on_title", sendApmNotification( "bluetooth_stays_on_title", "bluetooth_stays_on_message", APM_BT_NOTIFICATION); } catch (Exception e) { Loading @@ -194,7 +205,8 @@ public class BluetoothAirplaneModeListener { return; } } else { BluetoothStatsLog.write(BluetoothStatsLog.AIRPLANE_MODE_SESSION_REPORTED, BluetoothStatsLog.write( BluetoothStatsLog.AIRPLANE_MODE_SESSION_REPORTED, BluetoothStatsLog.AIRPLANE_MODE_SESSION_REPORTED__PACKAGE_NAME__BLUETOOTH, mIsBluetoothOnBeforeApmToggle, mIsBluetoothOnAfterApmToggle, Loading @@ -215,19 +227,22 @@ public class BluetoothAirplaneModeListener { // APM feature disabled or user has not used the feature yet by changing BT state in APM // BT will only remain on in APM when media profile is connected if (!apmEnhancementUsed && mAirplaneHelper.isBluetoothOn() if (!apmEnhancementUsed && mAirplaneHelper.isBluetoothOn() && mAirplaneHelper.isMediaProfileConnected()) { return true; } // APM feature enabled and user has used the feature by changing BT state in APM // BT will only remain on in APM based on user's last action in APM if (apmEnhancementUsed && mAirplaneHelper.isBluetoothOn() if (apmEnhancementUsed && mAirplaneHelper.isBluetoothOn() && mAirplaneHelper.isBluetoothOnAPM()) { return true; } // APM feature enabled and user has not used the feature yet by changing BT state in APM // BT will only remain on in APM if the default value is set to on if (isApmEnhancementEnabled() && !isBluetoothToggledOnApm() if (isApmEnhancementEnabled() && !isBluetoothToggledOnApm() && mAirplaneHelper.isBluetoothOn() && mAirplaneHelper.isBluetoothOnAPM()) { return true; Loading @@ -249,34 +264,30 @@ public class BluetoothAirplaneModeListener { } private boolean isFirstTimeNotification(String name) { return mAirplaneHelper.getSettingsSecureInt( name, NOTIFICATION_NOT_SHOWN) == NOTIFICATION_NOT_SHOWN; return mAirplaneHelper.getSettingsSecureInt(name, NOTIFICATION_NOT_SHOWN) == NOTIFICATION_NOT_SHOWN; } /** * Helper method to send APM notification */ /** Helper method to send APM notification */ public void sendApmNotification(String titleId, String messageId, String notificationState) throws PackageManager.NameNotFoundException { String btPackageName = mAirplaneHelper.getBluetoothPackageName(); if (btPackageName == null) { Log.e(TAG, "Unable to find Bluetooth package name with " + "APM notification resources"); Log.e( TAG, "Unable to find Bluetooth package name with " + "APM notification resources"); return; } Resources resources = mContext.getPackageManager() .getResourcesForApplication(btPackageName); Resources resources = mContext.getPackageManager().getResourcesForApplication(btPackageName); int title = resources.getIdentifier(titleId, "string", btPackageName); int message = resources.getIdentifier(messageId, "string", btPackageName); mNotificationManager.sendApmNotification( resources.getString(title), resources.getString(message)); mAirplaneHelper.setSettingsSecureInt(notificationState, NOTIFICATION_SHOWN); mAirplaneHelper.setSettingsSecureInt(notificationState, NOTIFICATION_SHOWN); } /** * Helper method to update whether user toggled Bluetooth in airplane mode */ /** Helper method to update whether user toggled Bluetooth in airplane mode */ public void updateBluetoothToggledTime() { if (!mUserToggledBluetoothDuringApm) { mUserToggledBluetoothDuringApmWithinMinute = Loading Loading
service/src/com/android/server/bluetooth/BluetoothAirplaneModeListener.java +57 −46 Original line number Diff line number Diff line Loading @@ -32,16 +32,19 @@ import com.android.bluetooth.BluetoothStatsLog; import com.android.internal.annotations.VisibleForTesting; /** * The BluetoothAirplaneModeListener handles system airplane mode change callback and checks * whether we need to inform BluetoothManagerService on this change. * The BluetoothAirplaneModeListener handles system airplane mode change callback and checks whether * we need to inform BluetoothManagerService on this change. * * The information of airplane mode turns on would not be passed to the BluetoothManagerService * <p>The information of airplane mode turns on would not be passed to the BluetoothManagerService * when Bluetooth is on and Bluetooth is in one of the following situations: * 1. Bluetooth A2DP is connected. * 2. Bluetooth Hearing Aid profile is connected. * 3. Bluetooth LE Audio is connected * * <ul> * <li>Bluetooth A2DP is connected. * <li>Bluetooth Hearing Aid profile is connected. * <li>Bluetooth LE Audio is connected * </ul> */ public class BluetoothAirplaneModeListener { class BluetoothAirplaneModeListener { private static final String TAG = "BluetoothAirplaneModeListener"; @VisibleForTesting static final String TOAST_COUNT = "bluetooth_airplane_toast_count"; Loading Loading @@ -89,21 +92,27 @@ public class BluetoothAirplaneModeListener { @VisibleForTesting int mToastCount = 0; BluetoothAirplaneModeListener(BluetoothManagerService service, Looper looper, Context context, BluetoothAirplaneModeListener( BluetoothManagerService service, Looper looper, Context context, BluetoothNotificationManager notificationManager) { mBluetoothManager = service; mNotificationManager = notificationManager; mContext = context; mHandler = new BluetoothAirplaneModeHandler(looper); context.getContentResolver().registerContentObserver( Settings.Global.getUriFor(Settings.Global.AIRPLANE_MODE_ON), true, context.getContentResolver() .registerContentObserver( Settings.Global.getUriFor(Settings.Global.AIRPLANE_MODE_ON), true, mAirplaneModeObserver); } private final ContentObserver mAirplaneModeObserver = new ContentObserver(null) { private final ContentObserver mAirplaneModeObserver = new ContentObserver(null) { @Override public void onChange(boolean unused) { public void onChange(boolean selfChange) { // Post from system main thread to android_io thread. Message msg = mHandler.obtainMessage(MSG_AIRPLANE_MODE_CHANGED); mHandler.sendMessage(msg); Loading @@ -128,9 +137,7 @@ public class BluetoothAirplaneModeListener { } } /** * Call after boot complete */ /** Call after boot complete */ @VisibleForTesting void start(BluetoothModeChangeHelper helper) { Log.i(TAG, "start"); Loading Loading @@ -164,7 +171,8 @@ public class BluetoothAirplaneModeListener { // Airplane mode enabled when Bluetooth is being used for audio/headering aid. // Bluetooth is not disabled in such case, only state is changed to // BLUETOOTH_ON_AIRPLANE mode. mAirplaneHelper.setSettingsInt(Settings.Global.BLUETOOTH_ON, mAirplaneHelper.setSettingsInt( Settings.Global.BLUETOOTH_ON, BluetoothManagerService.BLUETOOTH_ON_AIRPLANE); if (!isApmEnhancementEnabled() || !isBluetoothToggledOnApm()) { if (shouldPopToast()) { Loading @@ -173,17 +181,20 @@ public class BluetoothAirplaneModeListener { } else { if (isWifiEnabledOnApm() && isFirstTimeNotification(APM_WIFI_BT_NOTIFICATION)) { try { sendApmNotification("bluetooth_and_wifi_stays_on_title", sendApmNotification( "bluetooth_and_wifi_stays_on_title", "bluetooth_and_wifi_stays_on_message", APM_WIFI_BT_NOTIFICATION); } catch (Exception e) { Log.e(TAG, Log.e( TAG, "APM enhancement BT and Wi-Fi stays on notification not shown"); } } else if (!isWifiEnabledOnApm() && isFirstTimeNotification( APM_BT_NOTIFICATION)) { } else if (!isWifiEnabledOnApm() && isFirstTimeNotification(APM_BT_NOTIFICATION)) { try { sendApmNotification("bluetooth_stays_on_title", sendApmNotification( "bluetooth_stays_on_title", "bluetooth_stays_on_message", APM_BT_NOTIFICATION); } catch (Exception e) { Loading @@ -194,7 +205,8 @@ public class BluetoothAirplaneModeListener { return; } } else { BluetoothStatsLog.write(BluetoothStatsLog.AIRPLANE_MODE_SESSION_REPORTED, BluetoothStatsLog.write( BluetoothStatsLog.AIRPLANE_MODE_SESSION_REPORTED, BluetoothStatsLog.AIRPLANE_MODE_SESSION_REPORTED__PACKAGE_NAME__BLUETOOTH, mIsBluetoothOnBeforeApmToggle, mIsBluetoothOnAfterApmToggle, Loading @@ -215,19 +227,22 @@ public class BluetoothAirplaneModeListener { // APM feature disabled or user has not used the feature yet by changing BT state in APM // BT will only remain on in APM when media profile is connected if (!apmEnhancementUsed && mAirplaneHelper.isBluetoothOn() if (!apmEnhancementUsed && mAirplaneHelper.isBluetoothOn() && mAirplaneHelper.isMediaProfileConnected()) { return true; } // APM feature enabled and user has used the feature by changing BT state in APM // BT will only remain on in APM based on user's last action in APM if (apmEnhancementUsed && mAirplaneHelper.isBluetoothOn() if (apmEnhancementUsed && mAirplaneHelper.isBluetoothOn() && mAirplaneHelper.isBluetoothOnAPM()) { return true; } // APM feature enabled and user has not used the feature yet by changing BT state in APM // BT will only remain on in APM if the default value is set to on if (isApmEnhancementEnabled() && !isBluetoothToggledOnApm() if (isApmEnhancementEnabled() && !isBluetoothToggledOnApm() && mAirplaneHelper.isBluetoothOn() && mAirplaneHelper.isBluetoothOnAPM()) { return true; Loading @@ -249,34 +264,30 @@ public class BluetoothAirplaneModeListener { } private boolean isFirstTimeNotification(String name) { return mAirplaneHelper.getSettingsSecureInt( name, NOTIFICATION_NOT_SHOWN) == NOTIFICATION_NOT_SHOWN; return mAirplaneHelper.getSettingsSecureInt(name, NOTIFICATION_NOT_SHOWN) == NOTIFICATION_NOT_SHOWN; } /** * Helper method to send APM notification */ /** Helper method to send APM notification */ public void sendApmNotification(String titleId, String messageId, String notificationState) throws PackageManager.NameNotFoundException { String btPackageName = mAirplaneHelper.getBluetoothPackageName(); if (btPackageName == null) { Log.e(TAG, "Unable to find Bluetooth package name with " + "APM notification resources"); Log.e( TAG, "Unable to find Bluetooth package name with " + "APM notification resources"); return; } Resources resources = mContext.getPackageManager() .getResourcesForApplication(btPackageName); Resources resources = mContext.getPackageManager().getResourcesForApplication(btPackageName); int title = resources.getIdentifier(titleId, "string", btPackageName); int message = resources.getIdentifier(messageId, "string", btPackageName); mNotificationManager.sendApmNotification( resources.getString(title), resources.getString(message)); mAirplaneHelper.setSettingsSecureInt(notificationState, NOTIFICATION_SHOWN); mAirplaneHelper.setSettingsSecureInt(notificationState, NOTIFICATION_SHOWN); } /** * Helper method to update whether user toggled Bluetooth in airplane mode */ /** Helper method to update whether user toggled Bluetooth in airplane mode */ public void updateBluetoothToggledTime() { if (!mUserToggledBluetoothDuringApm) { mUserToggledBluetoothDuringApmWithinMinute = Loading