summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--AndroidManifest_cm.xml22
-rw-r--r--src/com/android/dialer/CallerInfoSettingsMigrationReceiver.java110
-rw-r--r--src/com/android/dialer/SystemUpdateReceiver.java35
3 files changed, 165 insertions, 2 deletions
diff --git a/AndroidManifest_cm.xml b/AndroidManifest_cm.xml
index e2b616f70..a7790e2c8 100644
--- a/AndroidManifest_cm.xml
+++ b/AndroidManifest_cm.xml
@@ -30,11 +30,10 @@
<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />
<uses-permission android:name="android.permission.READ_PRIVILEGED_PHONE_STATE" />
<uses-permission android:name="android.permission.READ_PRECISE_PHONE_STATE" />
-
<uses-permission android:name="com.cyanogen.ambient.permission.BIND_CALLER_INFO" />
-
<uses-permission android:name="android.permission.INTERACT_ACROSS_USERS" />
<uses-permission android:name="android.permission.MANAGE_USERS" />
+ <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<application>
@@ -56,6 +55,25 @@
</intent-filter>
</receiver>
+ <receiver
+ android:name="com.android.dialer.SystemUpdateReceiver">
+ <intent-filter>
+ <action android:name="android.intent.action.PRE_BOOT_COMPLETED" />
+ </intent-filter>
+ </receiver>
+
+ <receiver
+ android:name="com.android.dialer.CallerInfoSettingsMigrationReceiver"
+ android:enabled="false">
+ <intent-filter>
+ <action android:name="android.intent.action.BOOT_COMPLETED"/>
+ </intent-filter>
+ </receiver>
+
+ <service
+ android:name="com.android.dialer.CallerInfoSettingsMigrationReceiver$CallerInfoSettingsMigrationService"
+ android:exported="false" />
+
<service android:name=".discovery.DiscoveryService" />
<activity
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);
+ }
+ }
+
+}