summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRohit Yengisetty <rohit@cyngn.com>2016-05-24 11:15:14 -0700
committerRohit Yengisetty <rohit@cyngn.com>2016-05-25 18:34:48 -0700
commit5b9db20b71bab5a9ca71e07ace633a8a8d5c9e56 (patch)
tree6fcc3d8c30b3733ac0bd9962c6b2220fcb801d2b /src
parent560f3a8913457dbdda7fb9b90be9b2bda56b31e3 (diff)
downloadandroid_packages_apps_Dialer-5b9db20b71bab5a9ca71e07ace633a8a8d5c9e56.tar.gz
android_packages_apps_Dialer-5b9db20b71bab5a9ca71e07ace633a8a8d5c9e56.tar.bz2
android_packages_apps_Dialer-5b9db20b71bab5a9ca71e07ace633a8a8d5c9e56.zip
Add migrations for CallerInfo related settings
The settings related to CallerInfo Provider need to be migrated to a newer schema due to the changes within AmbientSDK and CallerInfoApi. The migration will take place on a system-update, alongside the installation of the newer AmbientSDK and AmbientCore. Issue-Id: CYNGNOS-2537 Change-Id: Iffa15d73b7616b27a9f80e5d2266ccdf56749f61
Diffstat (limited to 'src')
-rw-r--r--src/com/android/dialer/CallerInfoSettingsMigrationReceiver.java110
-rw-r--r--src/com/android/dialer/SystemUpdateReceiver.java35
2 files changed, 145 insertions, 0 deletions
diff --git a/src/com/android/dialer/CallerInfoSettingsMigrationReceiver.java b/src/com/android/dialer/CallerInfoSettingsMigrationReceiver.java
new file mode 100644
index 000000000..2dd9eacbc
--- /dev/null
+++ b/src/com/android/dialer/CallerInfoSettingsMigrationReceiver.java
@@ -0,0 +1,110 @@
+package com.android.dialer;
+
+import android.app.Service;
+import android.content.BroadcastReceiver;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.ServiceConnection;
+import android.content.pm.PackageManager;
+import android.os.IBinder;
+import android.os.RemoteException;
+import android.provider.Settings;
+import android.text.TextUtils;
+import com.cyanogen.ambient.callerinfo.extension.ICallerInfoPlugin;
+import com.cyanogen.ambient.callerinfo.util.CallerInfoHelper;
+import com.cyanogen.ambient.callerinfo.util.PluginStatus;
+import com.cyanogen.ambient.common.CyanogenAmbientUtil;
+
+import static com.cyanogen.ambient.callerinfo.util.SettingsConstants.PROVIDER_KEY_V2;
+import static com.cyanogen.ambient.callerinfo.util.SettingsConstants.PROVIDER_STATUS;
+
+/**
+ * A one-shot receiver that kicks off the task for performing the migration for any relevant
+ * CallerInfo related settings. If the user had previously enabled a CallerInfo Provider, those
+ * settings will be carried over to the new schema.
+ *
+ * The settings migration is necessitated because of the revisions in
+ * {@link com.cyanogen.ambient.callerinfo.CallerInfoApi}. For a detailed briefing on the new
+ * settings, refer to {@link com.cyanogen.ambient.callerinfo.util.SettingsListener.CallerInfoSettings}
+ */
+public class CallerInfoSettingsMigrationReceiver extends BroadcastReceiver {
+
+ @Override
+ public void onReceive(final Context context, Intent intent) {
+ if (CyanogenAmbientUtil.isCyanogenAmbientAvailable(context) ==
+ CyanogenAmbientUtil.SUCCESS) {
+ ComponentName provider = CallerInfoHelper.getActiveProviderPackage(context);
+ if (TextUtils.isEmpty(provider.flattenToString())) {
+ // there isn't an active provider to migrate to the new settings
+ return;
+ }
+
+ // start the service responsible for performing the migration task
+ Intent migrationService = new Intent();
+ migrationService.setClass(context, CallerInfoSettingsMigrationService.class);
+ context.startService(migrationService);
+ }
+ }
+
+ /**
+ * The Service doing the actual task of settings migration.
+ */
+ public static class CallerInfoSettingsMigrationService extends Service
+ implements ServiceConnection {
+
+ @Override
+ public IBinder onBind(Intent intent) {
+ return null;
+ }
+
+ @Override
+ public int onStartCommand(Intent intent, int flags, int startId) {
+ Intent pluginIntent = new Intent();
+ pluginIntent.setComponent(CallerInfoHelper.getActiveProviderPackage(this));
+ bindService(pluginIntent, this, Context.BIND_AUTO_CREATE);
+ return Service.START_REDELIVER_INTENT;
+ }
+
+ @Override
+ public void onServiceConnected(ComponentName name, IBinder service) {
+ ICallerInfoPlugin plugin = ICallerInfoPlugin.Stub.asInterface(service);
+ try {
+ if (plugin.isAuthenticated().getObject()) {
+ // write the active plugin to the new settings field
+ String value = name.flattenToString();
+ Settings.Secure.putString(getContentResolver(), PROVIDER_KEY_V2, value);
+ Settings.Secure.putInt(getContentResolver(), PROVIDER_STATUS,
+ PluginStatus.ACTIVE.ordinal());
+
+ // delete old setting
+ CallerInfoHelper.setActiveProvider(this, null);
+ }
+ } catch (RemoteException e) {
+ e.printStackTrace();
+ } finally {
+ performCleanup();
+ }
+ }
+
+ @Override
+ public void onServiceDisconnected(ComponentName name) {
+ performCleanup();
+ }
+
+ private void performCleanup() {
+ // disable migration receiver
+ ComponentName migrationReceiver = new ComponentName(this,
+ CallerInfoSettingsMigrationReceiver.class);
+ getPackageManager().setComponentEnabledSetting(migrationReceiver,
+ PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
+ PackageManager.DONT_KILL_APP);
+
+ // unbind from the caller-info plugin
+ unbindService(this);
+
+ // stop this service
+ stopSelf();
+ }
+ }
+}
diff --git a/src/com/android/dialer/SystemUpdateReceiver.java b/src/com/android/dialer/SystemUpdateReceiver.java
new file mode 100644
index 000000000..a932baf4a
--- /dev/null
+++ b/src/com/android/dialer/SystemUpdateReceiver.java
@@ -0,0 +1,35 @@
+package com.android.dialer;
+
+import android.content.BroadcastReceiver;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import com.cyanogen.ambient.common.CyanogenAmbientUtil;
+
+/**
+ * Receiver for system-updates.
+ */
+public class SystemUpdateReceiver extends BroadcastReceiver {
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ if (CyanogenAmbientUtil.isCyanogenAmbientAvailable(context) ==
+ CyanogenAmbientUtil.SUCCESS) {
+ // Enable the receiver that performs the migration for CallerInfo related settings
+ //
+ // This component was disabled by default and only activated on system-updates.
+ // We also need to ensure that any caller-info plugin update is installed before
+ // proceeding w/ the settings migration, as the Service responsible for the settings
+ // migration needs to bind to the plugin to query information additional
+ // information needed to populate the settings correctly.
+ ComponentName migrationReceiver = new ComponentName(context,
+ CallerInfoSettingsMigrationReceiver.class);
+ PackageManager packageManager = context.getPackageManager();
+ packageManager.setComponentEnabledSetting(migrationReceiver,
+ PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
+ PackageManager.DONT_KILL_APP);
+ }
+ }
+
+}