diff options
Diffstat (limited to 'src/com/android')
4 files changed, 47 insertions, 6 deletions
diff --git a/src/com/android/cellbroadcastreceiver/CellBroadcastAlertReminder.java b/src/com/android/cellbroadcastreceiver/CellBroadcastAlertReminder.java index 33632c908..2f58edcd5 100644 --- a/src/com/android/cellbroadcastreceiver/CellBroadcastAlertReminder.java +++ b/src/com/android/cellbroadcastreceiver/CellBroadcastAlertReminder.java @@ -129,7 +129,8 @@ public class CellBroadcastAlertReminder extends Service { * * @return true if a pending reminder was set; false if there are no more reminders */ - static boolean queueAlertReminder(Context context, int subId, boolean firstTime) { + @VisibleForTesting + public static boolean queueAlertReminder(Context context, int subId, boolean firstTime) { // Stop any alert reminder sound and cancel any previously queued reminders. cancelAlertReminder(); diff --git a/src/com/android/cellbroadcastreceiver/CellBroadcastChannelManager.java b/src/com/android/cellbroadcastreceiver/CellBroadcastChannelManager.java index 32d93f9e7..178b026b6 100644 --- a/src/com/android/cellbroadcastreceiver/CellBroadcastChannelManager.java +++ b/src/com/android/cellbroadcastreceiver/CellBroadcastChannelManager.java @@ -92,8 +92,8 @@ public class CellBroadcastChannelManager { private static final String KEY_ALERT_DURATION = "alert_duration"; /** Defines if Do Not Disturb should be overridden for this alert */ private static final String KEY_OVERRIDE_DND = "override_dnd"; - /** Defines whether writing alert message to SMS inbox. */ - private static final String KEY_WRITE_TO_SMS_INBOX = "write_to_sms_inbox"; + /** Defines whether writing alert message should exclude from SMS inbox. */ + private static final String KEY_EXCLUDE_FROM_SMS_INBOX = "exclude_from_sms_inbox"; /** * Defines whether the channel needs language filter or not. True indicates that the alert @@ -122,7 +122,9 @@ public class CellBroadcastChannelManager { // by default no custom alert duration. play the alert tone with the tone's duration. public int mAlertDuration = -1; public boolean mOverrideDnd = false; - public boolean mWriteToSmsInbox = false; + // If enable_write_alerts_to_sms_inbox is true, write to sms inbox is enabled by default + // for all channels except for channels which explicitly set to exclude from sms inbox. + public boolean mWriteToSmsInbox = true; public CellBroadcastChannelRange(Context context, int subId, String channelRange) { @@ -192,9 +194,9 @@ public class CellBroadcastChannelManager { mOverrideDnd = true; } break; - case KEY_WRITE_TO_SMS_INBOX: + case KEY_EXCLUDE_FROM_SMS_INBOX: if (value.equalsIgnoreCase("true")) { - mWriteToSmsInbox = true; + mWriteToSmsInbox = false; } break; } diff --git a/src/com/android/cellbroadcastreceiver/CellBroadcastConfigService.java b/src/com/android/cellbroadcastreceiver/CellBroadcastConfigService.java index be5d38a23..c290dd809 100644 --- a/src/com/android/cellbroadcastreceiver/CellBroadcastConfigService.java +++ b/src/com/android/cellbroadcastreceiver/CellBroadcastConfigService.java @@ -34,6 +34,7 @@ import androidx.annotation.NonNull; import com.android.cellbroadcastreceiver.CellBroadcastChannelManager.CellBroadcastChannelRange; import com.android.internal.annotations.VisibleForTesting; +import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -98,6 +99,23 @@ public class CellBroadcastConfigService extends IntentService { return subIds; } + private void resetCellBroadcastChannels(int subId) { + SmsManager manager; + if (subId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { + manager = SmsManager.getSmsManagerForSubscriptionId(subId); + } else { + manager = SmsManager.getDefault(); + } + + // TODO: Call manager.resetAllCellBroadcastRanges() in Android S. + try { + Method method = SmsManager.class.getDeclaredMethod("resetAllCellBroadcastRanges"); + method.invoke(manager); + } catch (Exception e) { + log("Can't reset cell broadcast ranges. e=" + e); + } + } + /** * Enable cell broadcast messages channels. Messages can be only received on the * enabled channels. @@ -106,6 +124,7 @@ public class CellBroadcastConfigService extends IntentService { */ @VisibleForTesting public void enableCellBroadcastChannels(int subId) { + resetCellBroadcastChannels(subId); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); Resources res = CellBroadcastSettings.getResources(this, subId); diff --git a/src/com/android/cellbroadcastreceiver/CellBroadcastSearchIndexableProvider.java b/src/com/android/cellbroadcastreceiver/CellBroadcastSearchIndexableProvider.java index 3d56f7b05..16dbc2649 100644 --- a/src/com/android/cellbroadcastreceiver/CellBroadcastSearchIndexableProvider.java +++ b/src/com/android/cellbroadcastreceiver/CellBroadcastSearchIndexableProvider.java @@ -38,6 +38,7 @@ import static android.provider.SearchIndexablesContract.NON_INDEXABLES_KEYS_COLU import android.annotation.Nullable; import android.content.Context; import android.content.Intent; +import android.content.pm.PackageManager; import android.content.res.Resources; import android.database.Cursor; import android.database.MatrixCursor; @@ -108,6 +109,10 @@ public class CellBroadcastSearchIndexableProvider extends SearchIndexablesProvid @Override public Cursor queryXmlResources(String[] projection) { + if (isAutomotive()) { + return null; + } + MatrixCursor cursor = new MatrixCursor(INDEXABLES_XML_RES_COLUMNS); final int count = INDEXABLE_RES.length; for (int n = 0; n < count; n++) { @@ -126,6 +131,10 @@ public class CellBroadcastSearchIndexableProvider extends SearchIndexablesProvid @Override public Cursor queryRawData(String[] projection) { + if (isAutomotive()) { + return null; + } + MatrixCursor cursor = new MatrixCursor(INDEXABLES_RAW_COLUMNS); final Resources res = getResourcesMethod(); @@ -255,4 +264,14 @@ public class CellBroadcastSearchIndexableProvider extends SearchIndexablesProvid return cursor; } + + /** + * Whether or not this is an Android Automotive platform. + * @return true if the current platform is automotive + */ + @VisibleForTesting + public boolean isAutomotive() { + return getContextMethod().getPackageManager().hasSystemFeature( + PackageManager.FEATURE_AUTOMOTIVE); + } } |