2828import android .os .Parcel ;
2929import android .os .Parcelable ;
3030import android .util .AttributeSet ;
31+ import android .util .TypedValue ;
3132import android .util .Xml ;
3233import android .view .accessibility .AccessibilityEvent ;
3334
@@ -182,9 +183,14 @@ public class AccessibilityServiceInfo implements Parcelable {
182183 private boolean mCanRetrieveWindowContent ;
183184
184185 /**
185- * Description of the accessibility service.
186+ * Resource id of the description of the accessibility service.
186187 */
187- private String mDescription ;
188+ private int mDescriptionResId ;
189+
190+ /**
191+ * Non localized description of the accessibility service.
192+ */
193+ private String mNonLocalizedDescription ;
188194
189195 /**
190196 * Creates a new instance.
@@ -256,8 +262,15 @@ public AccessibilityServiceInfo(ResolveInfo resolveInfo, Context context)
256262 mCanRetrieveWindowContent = asAttributes .getBoolean (
257263 com .android .internal .R .styleable .AccessibilityService_canRetrieveWindowContent ,
258264 false );
259- mDescription = asAttributes .getString (
265+ TypedValue peekedValue = asAttributes .peekValue (
260266 com .android .internal .R .styleable .AccessibilityService_description );
267+ if (peekedValue != null ) {
268+ mDescriptionResId = peekedValue .resourceId ;
269+ CharSequence nonLocalizedDescription = peekedValue .coerceToString ();
270+ if (nonLocalizedDescription != null ) {
271+ mNonLocalizedDescription = nonLocalizedDescription .toString ().trim ();
272+ }
273+ }
261274 asAttributes .recycle ();
262275 } catch (NameNotFoundException e ) {
263276 throw new XmlPullParserException ( "Unable to create context for: "
@@ -331,15 +344,38 @@ public boolean getCanRetrieveWindowContent() {
331344 }
332345
333346 /**
334- * Description of the accessibility service.
347+ * Gets the non-localized description of the accessibility service.
335348 * <p>
336349 * <strong>Statically set from
337350 * {@link AccessibilityService#SERVICE_META_DATA meta-data}.</strong>
338351 * </p>
339352 * @return The description.
353+ *
354+ * @deprecated Use {@link #loadDescription(PackageManager)}.
340355 */
341356 public String getDescription () {
342- return mDescription ;
357+ return mNonLocalizedDescription ;
358+ }
359+
360+ /**
361+ * The localized description of the accessibility service.
362+ * <p>
363+ * <strong>Statically set from
364+ * {@link AccessibilityService#SERVICE_META_DATA meta-data}.</strong>
365+ * </p>
366+ * @return The localized description.
367+ */
368+ public String loadDescription (PackageManager packageManager ) {
369+ if (mDescriptionResId == 0 ) {
370+ return mNonLocalizedDescription ;
371+ }
372+ ServiceInfo serviceInfo = mResolveInfo .serviceInfo ;
373+ CharSequence description = packageManager .getText (serviceInfo .packageName ,
374+ mDescriptionResId , serviceInfo .applicationInfo );
375+ if (description != null ) {
376+ return description .toString ().trim ();
377+ }
378+ return null ;
343379 }
344380
345381 /**
@@ -359,7 +395,8 @@ public void writeToParcel(Parcel parcel, int flagz) {
359395 parcel .writeParcelable (mResolveInfo , 0 );
360396 parcel .writeString (mSettingsActivityName );
361397 parcel .writeInt (mCanRetrieveWindowContent ? 1 : 0 );
362- parcel .writeString (mDescription );
398+ parcel .writeInt (mDescriptionResId );
399+ parcel .writeString (mNonLocalizedDescription );
363400 }
364401
365402 private void initFromParcel (Parcel parcel ) {
@@ -372,7 +409,8 @@ private void initFromParcel(Parcel parcel) {
372409 mResolveInfo = parcel .readParcelable (null );
373410 mSettingsActivityName = parcel .readString ();
374411 mCanRetrieveWindowContent = (parcel .readInt () == 1 );
375- mDescription = parcel .readString ();
412+ mDescriptionResId = parcel .readInt ();
413+ mNonLocalizedDescription = parcel .readString ();
376414 }
377415
378416 @ Override
0 commit comments