@@ -78,7 +78,7 @@ public void handleMessage(Message msg) {
78
78
}
79
79
case MSG_CAN_SET_APPLICATION_RESTRICTIONS : {
80
80
String callingPackage = mContext .getPackageManager ().getNameForUid (msg .sendingUid );
81
- String managingPackage = getApplicationRestrictionsManagingPackage ();
81
+ String managingPackage = getApplicationRestrictionsManagingPackage (mContext );
82
82
Bundle responseBundle = new Bundle ();
83
83
responseBundle .putBoolean (KEY_CAN_SET_APPLICATION_RESTRICTIONS ,
84
84
callingPackage != null && callingPackage .equals (managingPackage ));
@@ -121,17 +121,18 @@ public void handleMessage(Message msg) {
121
121
* The supplied application restriction managing package must be installed when calling this
122
122
* API, otherwise an {@link IllegalArgumentException} will be thrown.
123
123
*/
124
- public void setApplicationRestrictionsManagingPackage (String packageName ) {
124
+ public static void setApplicationRestrictionsManagingPackage (Context context ,
125
+ String packageName ) {
125
126
if (packageName == null ) {
126
- PreferenceManager .getDefaultSharedPreferences (mContext ).edit ()
127
- .putStringSet (APPLICATION_RESTRICTIONS_MANAGING_PACKAGE_SIGNATURES_KEY , null );
128
- PreferenceManager . getDefaultSharedPreferences ( mContext ). edit ( )
129
- .putString ( APPLICATION_RESTRICTIONS_MANAGING_PACKAGE_KEY , null );
127
+ PreferenceManager .getDefaultSharedPreferences (context ).edit ()
128
+ .putStringSet (APPLICATION_RESTRICTIONS_MANAGING_PACKAGE_SIGNATURES_KEY , null )
129
+ . putString ( APPLICATION_RESTRICTIONS_MANAGING_PACKAGE_KEY , null )
130
+ .apply ( );
130
131
return ;
131
132
}
132
133
Signature [] signatures ;
133
134
try {
134
- PackageManager packageManager = mContext .getPackageManager ();
135
+ PackageManager packageManager = context .getPackageManager ();
135
136
PackageInfo packageInfo =
136
137
packageManager .getPackageInfo (packageName , PackageManager .GET_SIGNATURES );
137
138
if (packageInfo == null ) {
@@ -152,19 +153,19 @@ public void setApplicationRestrictionsManagingPackage(String packageName) {
152
153
signatureSet .add (signature .toCharsString ());
153
154
}
154
155
155
- PreferenceManager .getDefaultSharedPreferences (mContext ).edit ()
156
+ PreferenceManager .getDefaultSharedPreferences (context ).edit ()
156
157
.putStringSet (APPLICATION_RESTRICTIONS_MANAGING_PACKAGE_SIGNATURES_KEY ,
157
- signatureSet );
158
- PreferenceManager . getDefaultSharedPreferences ( mContext ). edit ( )
159
- .putString ( APPLICATION_RESTRICTIONS_MANAGING_PACKAGE_KEY , packageName );
158
+ signatureSet )
159
+ . putString ( APPLICATION_RESTRICTIONS_MANAGING_PACKAGE_KEY , packageName )
160
+ .apply ( );
160
161
}
161
162
162
163
/**
163
164
* Called by a profile owner or device owner to retrieve the application restrictions managing
164
165
* package for the current user, or {@code null} if none is set.
165
166
*/
166
- public String getApplicationRestrictionsManagingPackage (){
167
- return PreferenceManager .getDefaultSharedPreferences (mContext )
167
+ public static String getApplicationRestrictionsManagingPackage (Context context ){
168
+ return PreferenceManager .getDefaultSharedPreferences (context )
168
169
.getString (APPLICATION_RESTRICTIONS_MANAGING_PACKAGE_KEY , null );
169
170
}
170
171
@@ -194,7 +195,7 @@ private Bundle getApplicationRestrictions(String packageName){
194
195
195
196
/**
196
197
* Checks that the message sent through the bound service was sent by the same package as
197
- * declared in {@link #setApplicationRestrictionsManagingPackage(String)}, and
198
+ * declared in {@link #setApplicationRestrictionsManagingPackage(Context, String)}, and
198
199
* that its signature has not changed since it was set.
199
200
*
200
201
* @param callerUid the UID of the caller
@@ -204,7 +205,7 @@ private Bundle getApplicationRestrictions(String packageName){
204
205
* set.
205
206
*/
206
207
private void ensureCallerSignature (int callerUid ) {
207
- String appRestrictionsManagingPackage = getApplicationRestrictionsManagingPackage ();
208
+ String appRestrictionsManagingPackage = getApplicationRestrictionsManagingPackage (mContext );
208
209
if (appRestrictionsManagingPackage == null ) {
209
210
throw new SecurityException ("Caller is not app restrictions managing package" );
210
211
}
0 commit comments