summaryrefslogtreecommitdiffstats
path: root/src/com/android/settings/AllowBindAppWidgetActivity.java
diff options
context:
space:
mode:
authorSvet Ganov <svetoslavganov@google.com>2014-08-01 15:06:43 -0700
committerSvetoslav <svetoslavganov@google.com>2014-08-05 15:21:25 -0700
commitc15c0c078e65dfd8c10cf646fcd556cc26a6f62d (patch)
tree84642c60af841f8e4989b3ad10bbd67f0b9a44c5 /src/com/android/settings/AllowBindAppWidgetActivity.java
parent1f4049edfe1937ce19c7d93a5576ea03db83ad50 (diff)
downloadpackages_apps_Settings-c15c0c078e65dfd8c10cf646fcd556cc26a6f62d.zip
packages_apps_Settings-c15c0c078e65dfd8c10cf646fcd556cc26a6f62d.tar.gz
packages_apps_Settings-c15c0c078e65dfd8c10cf646fcd556cc26a6f62d.tar.bz2
Add support for widgets in user profiles
bug:14991269 Change-Id: I7f71787bf5e5278230063b9d3bafac96a0680682
Diffstat (limited to 'src/com/android/settings/AllowBindAppWidgetActivity.java')
-rw-r--r--src/com/android/settings/AllowBindAppWidgetActivity.java40
1 files changed, 26 insertions, 14 deletions
diff --git a/src/com/android/settings/AllowBindAppWidgetActivity.java b/src/com/android/settings/AllowBindAppWidgetActivity.java
index f05c1c2..c3bf78a 100644
--- a/src/com/android/settings/AllowBindAppWidgetActivity.java
+++ b/src/com/android/settings/AllowBindAppWidgetActivity.java
@@ -25,7 +25,7 @@ import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
-import android.util.DisplayMetrics;
+import android.os.UserHandle;
import android.util.Log;
import android.view.LayoutInflater;
import android.widget.CheckBox;
@@ -42,6 +42,7 @@ public class AllowBindAppWidgetActivity extends AlertActivity implements
private CheckBox mAlwaysUse;
private int mAppWidgetId;
+ private UserHandle mProfile;
private ComponentName mComponentName;
private String mCallingPackage;
private AppWidgetManager mAppWidgetManager;
@@ -55,27 +56,32 @@ public class AllowBindAppWidgetActivity extends AlertActivity implements
setResult(RESULT_CANCELED);
if (mAppWidgetId != -1 && mComponentName != null && mCallingPackage != null) {
try {
- mAppWidgetManager.bindAppWidgetId(mAppWidgetId, mComponentName);
- Intent result = new Intent();
- result.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId);
- setResult(RESULT_OK, result);
+ final boolean bound = mAppWidgetManager.bindAppWidgetIdIfAllowed(mAppWidgetId,
+ mProfile, mComponentName, null);
+ if (bound) {
+ Intent result = new Intent();
+ result.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId);
+ setResult(RESULT_OK, result);
+ }
} catch (Exception e) {
Log.v("BIND_APPWIDGET", "Error binding widget with id "
+ mAppWidgetId + " and component " + mComponentName);
}
- }
- boolean alwaysAllowBind = mAlwaysUse.isChecked();
- if (alwaysAllowBind != mAppWidgetManager.hasBindAppWidgetPermission(mCallingPackage)) {
- mAppWidgetManager.setBindAppWidgetPermission(mCallingPackage, alwaysAllowBind);
+
+ final boolean alwaysAllowBind = mAlwaysUse.isChecked();
+ if (alwaysAllowBind != mAppWidgetManager.hasBindAppWidgetPermission(
+ mCallingPackage)) {
+ mAppWidgetManager.setBindAppWidgetPermission(mCallingPackage,
+ alwaysAllowBind);
+ }
}
}
finish();
}
- protected void onDestroy() {
- if (!mClicked) {
+ protected void onPause() {
+ if (isDestroyed() && !mClicked) {
setResult(RESULT_CANCELED);
- finish();
}
super.onDestroy();
}
@@ -87,7 +93,12 @@ public class AllowBindAppWidgetActivity extends AlertActivity implements
if (intent != null) {
try {
mAppWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
- mComponentName = (ComponentName)
+ mProfile = intent.getParcelableExtra(
+ AppWidgetManager.EXTRA_APPWIDGET_PROVIDER_PROFILE);
+ if (mProfile == null) {
+ mProfile = android.os.Process.myUserHandle();
+ }
+ mComponentName =
intent.getParcelableExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER);
mCallingPackage = getCallingPackage();
PackageManager pm = getPackageManager();
@@ -123,7 +134,8 @@ public class AllowBindAppWidgetActivity extends AlertActivity implements
getResources().getDimension(R.dimen.bind_app_widget_dialog_checkbox_bottom_padding)));
mAppWidgetManager = AppWidgetManager.getInstance(this);
- mAlwaysUse.setChecked(mAppWidgetManager.hasBindAppWidgetPermission(mCallingPackage));
+ mAlwaysUse.setChecked(mAppWidgetManager.hasBindAppWidgetPermission(mCallingPackage,
+ mProfile.getIdentifier()));
setupAlert();
}