diff options
author | Chen Xu <fionaxu@google.com> | 2020-05-29 20:05:32 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2020-05-29 20:05:32 +0000 |
commit | a1d67318d40623e59a7732c9dffcdcb5110fbb39 (patch) | |
tree | c1d279fb97323775b8d7da4c1b12f6625480389b | |
parent | feec1a24f52bbd317dd55da50333754836ed98d0 (diff) | |
parent | 0f22394250c1f4af2939859ae574c3746e793c5e (diff) | |
download | CellBroadcastReceiver-a1d67318d40623e59a7732c9dffcdcb5110fbb39.tar.gz |
Merge "Allow OEMs to add CBR message history in application launcher" into rvc-dev
-rw-r--r-- | AndroidManifest.xml | 12 | ||||
-rw-r--r-- | AndroidManifest_Platform.xml | 12 | ||||
-rw-r--r-- | res/values/config.xml | 2 | ||||
-rw-r--r-- | res/values/overlayable.xml | 1 | ||||
-rw-r--r-- | src/com/android/cellbroadcastreceiver/CellBroadcastReceiver.java | 51 | ||||
-rw-r--r-- | tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastReceiverTest.java | 2 |
6 files changed, 80 insertions, 0 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml index d4a217666..dd4d7ca2f 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -88,6 +88,18 @@ </intent-filter> </activity> + <!-- Alias activity for CellBroadcastListActivity. Once enabled, it will appear in the launcher --> + <activity-alias android:name="com.android.cellbroadcastreceiver.CellBroadcastListLauncherActivity" + android:targetActivity="com.android.cellbroadcastreceiver.CellBroadcastListActivity" + android:enabled="false" + android:exported="true"> + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + <category android:name="android.intent.category.LAUNCHER" /> + <category android:name="android.intent.category.DEFAULT" /> + </intent-filter> + </activity-alias> + <!-- Settings opened by ListActivity menu, Settings app link or opt-out dialog. --> <activity android:name="com.android.cellbroadcastreceiver.CellBroadcastSettings" android:theme="@style/CellBroadcastSettingsTheme" diff --git a/AndroidManifest_Platform.xml b/AndroidManifest_Platform.xml index 45751fd43..7d17b055b 100644 --- a/AndroidManifest_Platform.xml +++ b/AndroidManifest_Platform.xml @@ -83,6 +83,18 @@ </intent-filter> </activity> + <!-- Alias activity for CellBroadcastListActivity. Once enabled, it will appear in the launcher --> + <activity-alias android:name="CellBroadcastListLauncherActivity" + android:targetActivity="CellBroadcastListActivity" + android:enabled="false" + android:exported="true"> + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + <category android:name="android.intent.category.LAUNCHER" /> + <category android:name="android.intent.category.DEFAULT" /> + </intent-filter> + </activity-alias> + <!-- Settings opened by ListActivity menu, Settings app link or opt-out dialog. --> <activity android:name="CellBroadcastSettings" android:theme="@style/CellBroadcastSettingsTheme" diff --git a/res/values/config.xml b/res/values/config.xml index a1dca5284..86d07b96d 100644 --- a/res/values/config.xml +++ b/res/values/config.xml @@ -80,6 +80,8 @@ <!-- Show area update info settings in CellBroadcastReceiver and information in SIM status in Settings app --> <!-- TODO: we have another copy of this config in framework which is consumed by settings. should clean this up as part of brazil 50 refactor --> <bool name="config_showAreaUpdateInfoSettings">false</bool> + <!-- Show cellbroadcast message history entry point in the application launcher.--> + <bool name="show_message_history_in_launcher">false</bool> <!-- Specify second language code to receive emergency alerts --> <string name="emergency_alert_second_language_code" translatable="false"></string> diff --git a/res/values/overlayable.xml b/res/values/overlayable.xml index 29d602987..97a034460 100644 --- a/res/values/overlayable.xml +++ b/res/values/overlayable.xml @@ -43,6 +43,7 @@ AOSP CBR app does not show presidential alert in settings, however OEM can choose to display a greyout presidential alert settings by overriding below config --> <item type="bool" name="show_presidential_alerts_settings" /> + <item type="bool" name="show_message_history_in_launcher" /> <!-- Some JP carriers requires to enable 0xA807 in additional_cbs_channels_strings but only for certain products. OEMs can customize below config by including 0xA807 diff --git a/src/com/android/cellbroadcastreceiver/CellBroadcastReceiver.java b/src/com/android/cellbroadcastreceiver/CellBroadcastReceiver.java index 27cfcaeec..15c1e2133 100644 --- a/src/com/android/cellbroadcastreceiver/CellBroadcastReceiver.java +++ b/src/com/android/cellbroadcastreceiver/CellBroadcastReceiver.java @@ -19,11 +19,15 @@ package com.android.cellbroadcastreceiver; import android.annotation.NonNull; import android.app.ActivityManager; import android.content.BroadcastReceiver; +import android.content.ComponentName; import android.content.ContentProviderClient; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; +import android.content.pm.ActivityInfo; +import android.content.pm.PackageInfo; +import android.content.pm.PackageManager; import android.content.res.Resources; import android.os.Bundle; import android.os.RemoteException; @@ -36,6 +40,7 @@ import android.telephony.CarrierConfigManager; import android.telephony.SubscriptionManager; import android.telephony.TelephonyManager; import android.telephony.cdma.CdmaSmsCbProgramData; +import android.text.TextUtils; import android.util.Log; import android.widget.Toast; @@ -109,6 +114,7 @@ public class CellBroadcastReceiver extends BroadcastReceiver { getCellBroadcastTask(deliveryTime); } else if (CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED.equals(action)) { initializeSharedPreference(); + enableLauncher(); startConfigService(); } else if (CELLBROADCAST_START_CONFIG_ACTION.equals(action) || SubscriptionManager.ACTION_DEFAULT_SMS_SUBSCRIPTION_CHANGED.equals(action)) { @@ -404,6 +410,51 @@ public class CellBroadcastReceiver extends BroadcastReceiver { } } + /** + * Enable Launcher. + */ + @VisibleForTesting + public void enableLauncher() { + boolean enable = getResourcesMethod().getBoolean(R.bool.show_message_history_in_launcher); + final PackageManager pm = mContext.getPackageManager(); + // This alias presents the target activity, CellBroadcastListActivity, as a independent + // entity with its own intent filter for android.intent.category.LAUNCHER. + // This alias will be enabled/disabled at run-time based on resource overlay. Once enabled, + // it will appear in the Launcher as a top-level application + String aliasLauncherActivity = null; + try { + PackageInfo p = pm.getPackageInfo(mContext.getPackageName(), + PackageManager.GET_ACTIVITIES | PackageManager.MATCH_DISABLED_COMPONENTS); + if (p != null) { + for (ActivityInfo activityInfo : p.activities) { + String targetActivity = activityInfo.targetActivity; + if (CellBroadcastListActivity.class.getName().equals(targetActivity)) { + aliasLauncherActivity = activityInfo.name; + break; + } + } + } + } catch (PackageManager.NameNotFoundException e) { + Log.e(TAG, e.toString()); + } + if (TextUtils.isEmpty(aliasLauncherActivity)) { + Log.e(TAG, "cannot find launcher activity"); + return; + } + + if (enable) { + Log.d(TAG, "enable launcher activity: " + aliasLauncherActivity); + pm.setComponentEnabledSetting( + new ComponentName(mContext, aliasLauncherActivity), + PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); + } else { + Log.d(TAG, "disable launcher activity: " + aliasLauncherActivity); + pm.setComponentEnabledSetting( + new ComponentName(mContext, aliasLauncherActivity), + PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); + } + } + private static void log(String msg) { Log.d(TAG, msg); } diff --git a/tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastReceiverTest.java b/tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastReceiverTest.java index 55172a851..95cb83701 100644 --- a/tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastReceiverTest.java +++ b/tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastReceiverTest.java @@ -111,9 +111,11 @@ public class CellBroadcastReceiverTest extends CellBroadcastTest { public void testOnReceive_actionCarrierConfigChanged() { doReturn(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED).when(mIntent).getAction(); doNothing().when(mCellBroadcastReceiver).initializeSharedPreference(); + doNothing().when(mCellBroadcastReceiver).enableLauncher(); mCellBroadcastReceiver.onReceive(mContext, mIntent); verify(mCellBroadcastReceiver).initializeSharedPreference(); verify(mCellBroadcastReceiver).startConfigService(); + verify(mCellBroadcastReceiver).enableLauncher(); } @Test |