| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.content.pm; |
| 18 |
|
| 19 |
import android.annotation.NonNull; |
| 20 |
import android.annotation.Nullable; |
| 21 |
import android.annotation.SystemApi; |
| 22 |
import android.graphics.drawable.Drawable; |
| 23 |
import android.os.Parcel; |
| 24 |
import android.os.Parcelable; |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
@SystemApi |
| 36 |
public final class InstantAppInfo implements Parcelable { |
| 37 |
private final ApplicationInfo mApplicationInfo; |
| 38 |
|
| 39 |
private final String mPackageName; |
| 40 |
private final CharSequence mLabelText; |
| 41 |
|
| 42 |
private final String[] mRequestedPermissions; |
| 43 |
private final String[] mGrantedPermissions; |
| 44 |
|
| 45 |
public InstantAppInfo(ApplicationInfo appInfo, |
| 46 |
String[] requestedPermissions, String[] grantedPermissions) { |
| 47 |
mApplicationInfo = appInfo; |
| 48 |
mPackageName = null; |
| 49 |
mLabelText = null; |
| 50 |
mRequestedPermissions = requestedPermissions; |
| 51 |
mGrantedPermissions = grantedPermissions; |
| 52 |
} |
| 53 |
|
| 54 |
public InstantAppInfo(String packageName, CharSequence label, |
| 55 |
String[] requestedPermissions, String[] grantedPermissions) { |
| 56 |
mApplicationInfo = null; |
| 57 |
mPackageName = packageName; |
| 58 |
mLabelText = label; |
| 59 |
mRequestedPermissions = requestedPermissions; |
| 60 |
mGrantedPermissions = grantedPermissions; |
| 61 |
} |
| 62 |
|
| 63 |
private InstantAppInfo(Parcel parcel) { |
| 64 |
mPackageName = parcel.readString(); |
| 65 |
mLabelText = parcel.readCharSequence(); |
| 66 |
mRequestedPermissions = parcel.readStringArray(); |
| 67 |
mGrantedPermissions = parcel.createStringArray(); |
| 68 |
mApplicationInfo = parcel.readParcelable(null, android.content.pm.ApplicationInfo.class); |
| 69 |
} |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
public @Nullable ApplicationInfo getApplicationInfo() { |
| 76 |
return mApplicationInfo; |
| 77 |
} |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
public @NonNull String getPackageName() { |
| 83 |
if (mApplicationInfo != null) { |
| 84 |
return mApplicationInfo.packageName; |
| 85 |
} |
| 86 |
return mPackageName; |
| 87 |
} |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
public @NonNull CharSequence loadLabel(@NonNull PackageManager packageManager) { |
| 94 |
if (mApplicationInfo != null) { |
| 95 |
return mApplicationInfo.loadLabel(packageManager); |
| 96 |
} |
| 97 |
return mLabelText; |
| 98 |
} |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
public @NonNull Drawable loadIcon(@NonNull PackageManager packageManager) { |
| 105 |
if (mApplicationInfo != null) { |
| 106 |
return mApplicationInfo.loadIcon(packageManager); |
| 107 |
} |
| 108 |
return packageManager.getInstantAppIcon(mPackageName); |
| 109 |
} |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
public @Nullable String[] getRequestedPermissions() { |
| 115 |
return mRequestedPermissions; |
| 116 |
} |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
public @Nullable String[] getGrantedPermissions() { |
| 122 |
return mGrantedPermissions; |
| 123 |
} |
| 124 |
|
| 125 |
@Override |
| 126 |
public int describeContents() { |
| 127 |
return 0; |
| 128 |
} |
| 129 |
|
| 130 |
@Override |
| 131 |
public void writeToParcel(Parcel parcel, int flags) { |
| 132 |
parcel.writeString(mPackageName); |
| 133 |
parcel.writeCharSequence(mLabelText); |
| 134 |
parcel.writeStringArray(mRequestedPermissions); |
| 135 |
parcel.writeStringArray(mGrantedPermissions); |
| 136 |
parcel.writeParcelable(mApplicationInfo, flags); |
| 137 |
} |
| 138 |
|
| 139 |
public static final @android.annotation.NonNull Creator<InstantAppInfo> CREATOR = |
| 140 |
new Creator<InstantAppInfo>() { |
| 141 |
@Override |
| 142 |
public InstantAppInfo createFromParcel(Parcel parcel) { |
| 143 |
return new InstantAppInfo(parcel); |
| 144 |
} |
| 145 |
|
| 146 |
@Override |
| 147 |
public InstantAppInfo[] newArray(int size) { |
| 148 |
return new InstantAppInfo[0]; |
| 149 |
} |
| 150 |
}; |
| 151 |
} |