Skip to content

Commit c8dc8eb

Browse files
mikejurkaAndroid (Google) Code Review
authored andcommitted
Merge "Use new keyguard appwidget picker" into jb-mr1-lockscreen-dev
2 parents 077105b + fc753c0 commit c8dc8eb

File tree

6 files changed

+104
-16
lines changed

6 files changed

+104
-16
lines changed

core/java/android/appwidget/AppWidgetManager.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ public class AppWidgetManager {
7979
*/
8080
public static final String ACTION_APPWIDGET_PICK = "android.appwidget.action.APPWIDGET_PICK";
8181

82+
/**
83+
* Similar to ACTION_APPWIDGET_PICK, but used from keyguard
84+
* @hide
85+
*/
86+
public static final String
87+
ACTION_KEYGUARD_APPWIDGET_PICK = "android.appwidget.action.KEYGUARD_APPWIDGET_PICK";
88+
8289
/**
8390
* Send this from your {@link AppWidgetHost} activity when you want to bind an AppWidget to
8491
* display and bindAppWidgetIdIfAllowed returns false.
@@ -223,13 +230,6 @@ public class AppWidgetManager {
223230
*/
224231
public static final String EXTRA_CATEGORY_FILTER = "categoryFilter";
225232

226-
/**
227-
* An intent extra to pass to the AppWidget picker which allows the picker to filter
228-
* the list based on the {@link AppWidgetProviderInfo#widgetFeatures}.
229-
* @hide
230-
*/
231-
public static final String EXTRA_FEATURES_FILTER = "featuresFilter";
232-
233233
/**
234234
* An intent extra to pass to the AppWidget picker to specify whether or not to sort
235235
* the list of caller-specified extra AppWidgets along with the rest of the AppWidgets

core/java/com/android/internal/widget/LockPatternUtils.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,11 @@ public class LockPatternUtils {
129129
*/
130130
public static final int ID_DEFAULT_STATUS_WIDGET = -2;
131131

132+
/**
133+
* Intent extra that's used to tag the default widget when using the picker
134+
*/
135+
public static final String EXTRA_DEFAULT_WIDGET = "com.android.settings.DEFAULT_WIDGET";
136+
132137
protected final static String LOCKOUT_PERMANENT_KEY = "lockscreen.lockedoutpermanently";
133138
protected final static String LOCKOUT_ATTEMPT_DEADLINE = "lockscreen.lockoutattemptdeadline";
134139
protected final static String PATTERN_EVER_CHOSEN_KEY = "lockscreen.patterneverchosen";

core/res/AndroidManifest.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1901,6 +1901,13 @@
19011901
android:description="@string/permdesc_bindGadget"
19021902
android:protectionLevel="signature|system" />
19031903

1904+
<!-- Private permission, to restrict who can bring up a dialog to add a new
1905+
keyguard widget
1906+
@hide -->
1907+
<permission android:name="android.permission.BIND_KEYGUARD_APPWIDGET"
1908+
android:permissionGroup="android.permission-group.PERSONAL_INFO"
1909+
android:protectionLevel="signature|system" />
1910+
19041911
<!-- Internal permission allowing an application to query/set which
19051912
applications can bind AppWidgets.
19061913
@hide -->

core/res/res/values/strings.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2065,6 +2065,15 @@
20652065
<!-- This can be used in any application wanting to disable the text "Emergency number" -->
20662066
<string name="emergency_call_dialog_number_for_display">Emergency number</string>
20672067

2068+
<!-- String to display if the clock status widget is selected (it is the default) [CHAR LIMIT=22] -->
2069+
<string name="widget_default" msgid="8269383575996003796">Clock</string>
2070+
2071+
<!-- Package name for default widget [DO NOT TRANSLATE] -->
2072+
<string name="widget_default_package_name">com.android.deskclock</string>
2073+
2074+
<!-- Class name for default widget [DO NOT TRANSLATE] -->
2075+
<string name="widget_default_class_name">com.android.deskclock.DeskClock</string>
2076+
20682077
<!--
20692078
*** touch based lock / unlock ***
20702079
--> <skip />

core/res/res/values/symbols.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,9 @@
479479
<java-symbol type="string" name="emailTypeOther" />
480480
<java-symbol type="string" name="emailTypeWork" />
481481
<java-symbol type="string" name="emergency_call_dialog_number_for_display" />
482+
<java-symbol type="string" name="widget_default" />
483+
<java-symbol type="string" name="widget_default_package_name" />
484+
<java-symbol type="string" name="widget_default_class_name" />
482485
<java-symbol type="string" name="emergency_calls_only" />
483486
<java-symbol type="string" name="enable_accessibility_canceled" />
484487
<java-symbol type="string" name="eventTypeAnniversary" />

policy/src/com/android/internal/policy/impl/keyguard/KeyguardHostView.java

Lines changed: 73 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,22 @@
2525
import android.appwidget.AppWidgetHostView;
2626
import android.appwidget.AppWidgetManager;
2727
import android.appwidget.AppWidgetProviderInfo;
28+
import android.content.ComponentName;
2829
import android.content.Context;
2930
import android.content.Intent;
3031
import android.content.IntentSender;
32+
import android.content.pm.ActivityInfo;
33+
import android.content.pm.PackageManager;
3134
import android.content.pm.UserInfo;
3235
import android.content.res.Resources;
3336
import android.graphics.Canvas;
3437
import android.graphics.Rect;
38+
import android.os.Bundle;
3539
import android.os.Looper;
3640
import android.os.Parcel;
3741
import android.os.Parcelable;
3842
import android.os.UserHandle;
3943
import android.os.UserManager;
40-
import android.provider.Settings;
4144
import android.util.AttributeSet;
4245
import android.util.Log;
4346
import android.util.Slog;
@@ -54,6 +57,7 @@
5457
import com.android.internal.widget.LockPatternUtils;
5558

5659
import java.io.File;
60+
import java.util.ArrayList;
5761
import java.util.List;
5862

5963
public class KeyguardHostView extends KeyguardViewBase {
@@ -880,14 +884,22 @@ public void onClick(View v) {
880884

881885
@Override
882886
public void run() {
883-
Intent intent = new Intent(Settings.ACTION_SECURITY_SETTINGS);
884-
intent.addFlags(
885-
Intent.FLAG_ACTIVITY_NEW_TASK
886-
| Intent.FLAG_ACTIVITY_SINGLE_TOP
887-
| Intent.FLAG_ACTIVITY_CLEAR_TOP
888-
| Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
889-
mContext.startActivityAsUser(intent,
890-
new UserHandle(UserHandle.USER_CURRENT));
887+
int defaultIconId = 0;
888+
Resources res = KeyguardHostView.this.getContext().getResources();
889+
ComponentName clock = new ComponentName(
890+
res.getString(R.string.widget_default_package_name),
891+
res.getString(R.string.widget_default_class_name));
892+
try {
893+
ActivityInfo activityInfo =
894+
mContext.getPackageManager().getActivityInfo(clock, 0);
895+
if (activityInfo != null) {
896+
defaultIconId = activityInfo.icon;
897+
}
898+
} catch (PackageManager.NameNotFoundException e) {
899+
defaultIconId = 0;
900+
}
901+
launchPickActivityIntent(R.string.widget_default, defaultIconId, clock,
902+
LockPatternUtils.EXTRA_DEFAULT_WIDGET);
891903
}
892904
});
893905
mCallback.dismiss(false);
@@ -898,6 +910,58 @@ public void run() {
898910
initializeTransportControl();
899911
}
900912

913+
private void launchPickActivityIntent(int defaultLabelId, int defaultIconId,
914+
ComponentName defaultComponentName, String defaultTag) {
915+
// Create intent to pick widget
916+
Intent pickIntent = new Intent(AppWidgetManager.ACTION_KEYGUARD_APPWIDGET_PICK);
917+
918+
int appWidgetId = mAppWidgetHost.allocateAppWidgetId();
919+
if (appWidgetId != -1) {
920+
pickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
921+
pickIntent.putExtra(AppWidgetManager.EXTRA_CUSTOM_SORT, false);
922+
pickIntent.putExtra(AppWidgetManager.EXTRA_CATEGORY_FILTER,
923+
AppWidgetProviderInfo.WIDGET_CATEGORY_KEYGUARD);
924+
925+
// Add an custom entry for the default
926+
AppWidgetProviderInfo defaultInfo = new AppWidgetProviderInfo();
927+
ArrayList<AppWidgetProviderInfo> extraInfos = new ArrayList<AppWidgetProviderInfo>();
928+
defaultInfo.label = getResources().getString(defaultLabelId);
929+
defaultInfo.icon = defaultIconId;
930+
defaultInfo.provider = defaultComponentName;
931+
extraInfos.add(defaultInfo);
932+
933+
ArrayList<Bundle> extraExtras = new ArrayList<Bundle>();
934+
Bundle b = new Bundle();
935+
b.putBoolean(defaultTag, true);
936+
extraExtras.add(b);
937+
938+
// Launch the widget picker
939+
pickIntent.putExtra(AppWidgetManager.EXTRA_CUSTOM_INFO, extraInfos);
940+
pickIntent.putExtra(AppWidgetManager.EXTRA_CUSTOM_EXTRAS, extraExtras);
941+
pickIntent.putExtra(Intent.EXTRA_INTENT, getBaseIntent());
942+
pickIntent.addFlags(
943+
Intent.FLAG_ACTIVITY_NEW_TASK
944+
| Intent.FLAG_ACTIVITY_SINGLE_TOP
945+
| Intent.FLAG_ACTIVITY_CLEAR_TOP
946+
| Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
947+
mContext.startActivityAsUser(pickIntent,
948+
new UserHandle(UserHandle.USER_CURRENT));
949+
} else {
950+
Log.e(TAG, "Unable to allocate an AppWidget id in lock screen");
951+
}
952+
}
953+
954+
private Intent getBaseIntent() {
955+
Intent baseIntent = new Intent(Intent.ACTION_MAIN, null);
956+
baseIntent.addCategory(Intent.CATEGORY_DEFAULT);
957+
958+
Bundle options = new Bundle();
959+
options.putInt(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY,
960+
AppWidgetProviderInfo.WIDGET_CATEGORY_KEYGUARD);
961+
baseIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
962+
return baseIntent;
963+
}
964+
901965
private void removeTransportFromWidgetPager() {
902966
int page = getWidgetPosition(R.id.keyguard_transport_control);
903967
if (page != -1) {

0 commit comments

Comments
 (0)