Merge "[SIM Dialog Migration] Sending push notification after DSDS reboot"
This commit is contained in:
@@ -3652,6 +3652,17 @@
|
|||||||
</intent-filter>
|
</intent-filter>
|
||||||
</receiver>
|
</receiver>
|
||||||
|
|
||||||
|
<receiver
|
||||||
|
android:name=".sim.receivers.SimCompleteBootReceiver"
|
||||||
|
android:exported="true">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.BOOT_COMPLETED"/>
|
||||||
|
</intent-filter>
|
||||||
|
</receiver>
|
||||||
|
|
||||||
|
<service android:name=".sim.SimNotificationService"
|
||||||
|
android:permission="android.permission.BIND_JOB_SERVICE" />
|
||||||
|
|
||||||
<!-- This is the longest AndroidManifest.xml ever. -->
|
<!-- This is the longest AndroidManifest.xml ever. -->
|
||||||
</application>
|
</application>
|
||||||
</manifest>
|
</manifest>
|
||||||
|
@@ -20,4 +20,5 @@
|
|||||||
<integer name="job_anomaly_config_update">101</integer>
|
<integer name="job_anomaly_config_update">101</integer>
|
||||||
<integer name="job_anomaly_detection">102</integer>
|
<integer name="job_anomaly_detection">102</integer>
|
||||||
<integer name="device_index_update">103</integer>
|
<integer name="device_index_update">103</integer>
|
||||||
|
<integer name="sim_notification_send">104</integer>
|
||||||
</resources>
|
</resources>
|
||||||
|
@@ -12093,6 +12093,17 @@
|
|||||||
<!-- Body text of DSDS activation failure dialog. Users could toggle the selected SIM again or reboot to recover. [CHAR LIMIT=NONE] -->
|
<!-- Body text of DSDS activation failure dialog. Users could toggle the selected SIM again or reboot to recover. [CHAR LIMIT=NONE] -->
|
||||||
<string name="dsds_activation_failure_body_msg2">Try turning on the SIM again. If the problem continues, restart your device.</string>
|
<string name="dsds_activation_failure_body_msg2">Try turning on the SIM again. If the problem continues, restart your device.</string>
|
||||||
|
|
||||||
|
<!-- Strings for SIM push notifications -->
|
||||||
|
<!-- Category name of the notifications related to SIM setup. [CHAR LIMIT=NONE] -->
|
||||||
|
<string name="sim_setup_channel_id">Network activation</string>
|
||||||
|
<!-- The title of post DSDS reboot notification. The title includes carrier's name. [CHAR LIMIT=NONE] -->
|
||||||
|
<string name="post_dsds_reboot_notification_title_with_carrier"><xliff:g id="carrier_name" example="Google Fi">%1$s</xliff:g> is active</string>
|
||||||
|
<!-- The body text of post DSDS reboot notification. [CHAR LIMIT=NONE] -->
|
||||||
|
<string name="post_dsds_reboot_notification_text">Tap to update SIM settings</string>
|
||||||
|
|
||||||
|
<!-- Button label of the removable sim card. [CHAR LIMIT=NONE] -->
|
||||||
|
<string name="sim_card_label">SIM card</string>
|
||||||
|
|
||||||
<!-- Strings for deleting eUICC subscriptions dialog activity -->
|
<!-- Strings for deleting eUICC subscriptions dialog activity -->
|
||||||
<!-- Title on confirmation dialog asking the user if they want to erase the downloaded SIM from the device. [CHAR_LIMIT=NONE] -->
|
<!-- Title on confirmation dialog asking the user if they want to erase the downloaded SIM from the device. [CHAR_LIMIT=NONE] -->
|
||||||
<string name="erase_sim_dialog_title">Erase this downloaded SIM?</string>
|
<string name="erase_sim_dialog_title">Erase this downloaded SIM?</string>
|
||||||
|
@@ -35,6 +35,7 @@ import com.android.settings.network.SubscriptionUtil;
|
|||||||
import com.android.settings.network.SwitchToEuiccSubscriptionSidecar;
|
import com.android.settings.network.SwitchToEuiccSubscriptionSidecar;
|
||||||
import com.android.settings.network.SwitchToRemovableSlotSidecar;
|
import com.android.settings.network.SwitchToRemovableSlotSidecar;
|
||||||
import com.android.settings.network.UiccSlotUtil;
|
import com.android.settings.network.UiccSlotUtil;
|
||||||
|
import com.android.settings.sim.SimActivationNotifier;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|
||||||
@@ -191,9 +192,8 @@ public class ToggleSubscriptionDialogActivity extends SubscriptionActionDialogAc
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Log.i(TAG, "User confirmed reboot to enable DSDS.");
|
Log.i(TAG, "User confirmed reboot to enable DSDS.");
|
||||||
|
SimActivationNotifier.setShowSimSettingsNotification(this, true);
|
||||||
mTelMgr.switchMultiSimConfig(NUM_OF_SIMS_FOR_DSDS);
|
mTelMgr.switchMultiSimConfig(NUM_OF_SIMS_FOR_DSDS);
|
||||||
// TODO(b/170507290): Store a bit in preferences for displaying the notification
|
|
||||||
// after the reboot.
|
|
||||||
break;
|
break;
|
||||||
case DIALOG_TAG_ENABLE_SIM_CONFIRMATION:
|
case DIALOG_TAG_ENABLE_SIM_CONFIRMATION:
|
||||||
Log.i(TAG, "User confirmed to enable the subscription.");
|
Log.i(TAG, "User confirmed to enable the subscription.");
|
||||||
|
144
src/com/android/settings/sim/SimActivationNotifier.java
Normal file
144
src/com/android/settings/sim/SimActivationNotifier.java
Normal file
@@ -0,0 +1,144 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2020 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.sim;
|
||||||
|
|
||||||
|
import static android.content.Context.MODE_PRIVATE;
|
||||||
|
|
||||||
|
import android.annotation.IntDef;
|
||||||
|
import android.app.Notification;
|
||||||
|
import android.app.NotificationChannel;
|
||||||
|
import android.app.NotificationManager;
|
||||||
|
import android.app.PendingIntent;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.telephony.SubscriptionInfo;
|
||||||
|
import android.telephony.SubscriptionManager;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import androidx.core.app.TaskStackBuilder;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.Settings;
|
||||||
|
import com.android.settings.network.SubscriptionUtil;
|
||||||
|
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class manages the notification of SIM activation notification including creating and
|
||||||
|
* canceling the notifications.
|
||||||
|
*/
|
||||||
|
public class SimActivationNotifier {
|
||||||
|
|
||||||
|
private static final String TAG = "SimActivationNotifier";
|
||||||
|
private static final String SIM_SETUP_CHANNEL_ID = "sim_setup";
|
||||||
|
private static final String SIM_PREFS = "sim_prefs";
|
||||||
|
private static final String KEY_SHOW_SIM_SETTINGS_NOTIFICATION =
|
||||||
|
"show_sim_settings_notification";
|
||||||
|
|
||||||
|
public static final int SIM_ACTIVATION_NOTIFICATION_ID = 1;
|
||||||
|
|
||||||
|
/** Notification types */
|
||||||
|
@Retention(RetentionPolicy.SOURCE)
|
||||||
|
@IntDef(
|
||||||
|
value = {
|
||||||
|
NotificationType.NETWORK_CONFIG,
|
||||||
|
})
|
||||||
|
public @interface NotificationType {
|
||||||
|
// The notification to remind users to config network Settings.
|
||||||
|
int NETWORK_CONFIG = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
private final Context mContext;
|
||||||
|
private final NotificationManager mNotificationManager;
|
||||||
|
|
||||||
|
public SimActivationNotifier(Context context) {
|
||||||
|
mContext = context;
|
||||||
|
mNotificationManager = context.getSystemService(NotificationManager.class);
|
||||||
|
mNotificationManager.createNotificationChannel(
|
||||||
|
new NotificationChannel(
|
||||||
|
SIM_SETUP_CHANNEL_ID,
|
||||||
|
mContext.getString(R.string.sim_setup_channel_id),
|
||||||
|
NotificationManager.IMPORTANCE_HIGH));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets whether Settings should send a push notification for the SIM activation.
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* @param showNotification whether Settings should send a push notification for the SIM
|
||||||
|
* activation.
|
||||||
|
*/
|
||||||
|
public static void setShowSimSettingsNotification(Context context, boolean showNotification) {
|
||||||
|
final SharedPreferences prefs = context.getSharedPreferences(SIM_PREFS, MODE_PRIVATE);
|
||||||
|
prefs.edit().putBoolean(KEY_SHOW_SIM_SETTINGS_NOTIFICATION, showNotification).apply();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets whether Settings should send a push notification for the SIM activation.
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* @return true if Settings should send a push notification for SIM activation. Otherwise,
|
||||||
|
* return false.
|
||||||
|
*/
|
||||||
|
public static boolean getShowSimSettingsNotification(Context context) {
|
||||||
|
final SharedPreferences prefs = context.getSharedPreferences(SIM_PREFS, MODE_PRIVATE);
|
||||||
|
return prefs.getBoolean(KEY_SHOW_SIM_SETTINGS_NOTIFICATION, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Sends a push notification for the SIM activation. It should be called after DSDS reboot. */
|
||||||
|
public void sendNetworkConfigNotification() {
|
||||||
|
SubscriptionManager subscriptionManager =
|
||||||
|
mContext.getSystemService(SubscriptionManager.class);
|
||||||
|
SubscriptionInfo activeRemovableSub =
|
||||||
|
SubscriptionUtil.getActiveSubscriptions(subscriptionManager).stream()
|
||||||
|
.filter(sub -> !sub.isEmbedded())
|
||||||
|
.findFirst()
|
||||||
|
.orElse(null);
|
||||||
|
|
||||||
|
if (activeRemovableSub == null) {
|
||||||
|
Log.e(TAG, "No removable subscriptions found. Do not show notification.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String carrierName =
|
||||||
|
TextUtils.isEmpty(activeRemovableSub.getDisplayName())
|
||||||
|
? mContext.getString(R.string.sim_card_label)
|
||||||
|
: activeRemovableSub.getDisplayName().toString();
|
||||||
|
String title =
|
||||||
|
mContext.getString(
|
||||||
|
R.string.post_dsds_reboot_notification_title_with_carrier, carrierName);
|
||||||
|
String text = mContext.getString(R.string.post_dsds_reboot_notification_text);
|
||||||
|
Intent clickIntent = new Intent(mContext, Settings.MobileNetworkListActivity.class);
|
||||||
|
TaskStackBuilder stackBuilder =
|
||||||
|
TaskStackBuilder.create(mContext).addNextIntent(clickIntent);
|
||||||
|
PendingIntent contentIntent =
|
||||||
|
stackBuilder.getPendingIntent(
|
||||||
|
0 /* requestCode */, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
|
|
||||||
|
Notification.Builder builder =
|
||||||
|
new Notification.Builder(mContext, SIM_SETUP_CHANNEL_ID)
|
||||||
|
.setContentTitle(title)
|
||||||
|
.setContentText(text)
|
||||||
|
.setContentIntent(contentIntent)
|
||||||
|
.setSmallIcon(R.drawable.ic_sim_alert)
|
||||||
|
.setAutoCancel(true);
|
||||||
|
mNotificationManager.notify(SIM_ACTIVATION_NOTIFICATION_ID, builder.build());
|
||||||
|
}
|
||||||
|
}
|
81
src/com/android/settings/sim/SimNotificationService.java
Normal file
81
src/com/android/settings/sim/SimNotificationService.java
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2020 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.sim;
|
||||||
|
|
||||||
|
import android.app.job.JobInfo;
|
||||||
|
import android.app.job.JobParameters;
|
||||||
|
import android.app.job.JobScheduler;
|
||||||
|
import android.app.job.JobService;
|
||||||
|
import android.content.ComponentName;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.PersistableBundle;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
|
||||||
|
/** A JobService sends SIM notifications. */
|
||||||
|
public class SimNotificationService extends JobService {
|
||||||
|
|
||||||
|
private static final String TAG = "SimNotificationService";
|
||||||
|
private static final String EXTRA_NOTIFICATION_TYPE = "notification_type";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Schedules a service to send SIM push notifications.
|
||||||
|
* @param context
|
||||||
|
* @param notificationType indicates which SIM notification to send.
|
||||||
|
*/
|
||||||
|
public static void scheduleSimNotification(
|
||||||
|
Context context, @SimActivationNotifier.NotificationType int notificationType) {
|
||||||
|
final JobScheduler jobScheduler =
|
||||||
|
context.getApplicationContext().getSystemService(JobScheduler.class);
|
||||||
|
final ComponentName component =
|
||||||
|
new ComponentName(context.getApplicationContext(), SimNotificationService.class);
|
||||||
|
PersistableBundle extra = new PersistableBundle();
|
||||||
|
extra.putInt(EXTRA_NOTIFICATION_TYPE, notificationType);
|
||||||
|
|
||||||
|
jobScheduler.schedule(
|
||||||
|
new JobInfo.Builder(R.integer.sim_notification_send, component)
|
||||||
|
.setExtras(extra)
|
||||||
|
.build());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onStartJob(JobParameters params) {
|
||||||
|
PersistableBundle extra = params.getExtras();
|
||||||
|
if (extra == null) {
|
||||||
|
Log.e(TAG, "Failed to get notification type.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
int notificationType = extra.getInt(EXTRA_NOTIFICATION_TYPE);
|
||||||
|
switch (notificationType) {
|
||||||
|
case SimActivationNotifier.NotificationType.NETWORK_CONFIG:
|
||||||
|
Log.i(TAG, "Sending SIM config notification.");
|
||||||
|
SimActivationNotifier.setShowSimSettingsNotification(this, false);
|
||||||
|
new SimActivationNotifier(this).sendNetworkConfigNotification();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Log.e(TAG, "Invalid notification type: " + notificationType);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onStopJob(JobParameters params) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2020 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.sim.receivers;
|
||||||
|
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.android.settings.sim.SimActivationNotifier;
|
||||||
|
import com.android.settings.sim.SimNotificationService;
|
||||||
|
|
||||||
|
/** This class manage all SIM operations after device boot up. */
|
||||||
|
public class SimCompleteBootReceiver extends BroadcastReceiver {
|
||||||
|
private static final String TAG = "SimCompleteBootReceiver";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
if (!Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
|
||||||
|
Log.e(TAG, "Invalid broadcast received.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (SimActivationNotifier.getShowSimSettingsNotification(context)) {
|
||||||
|
SimNotificationService.scheduleSimNotification(
|
||||||
|
context, SimActivationNotifier.NotificationType.NETWORK_CONFIG);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user