use of android.content.pm.ApplicationInfo in project android_frameworks_base by ResurrectionRemix.
the class BaseStatusBar method inflateViews.
protected boolean inflateViews(Entry entry, ViewGroup parent) {
PackageManager pmUser = getPackageManagerForUser(mContext, entry.notification.getUser().getIdentifier());
final StatusBarNotification sbn = entry.notification;
try {
entry.cacheContentViews(mContext, null);
} catch (RuntimeException e) {
Log.e(TAG, "Unable to get notification remote views", e);
return false;
}
final RemoteViews contentView = entry.cachedContentView;
final RemoteViews bigContentView = entry.cachedBigContentView;
final RemoteViews headsUpContentView = entry.cachedHeadsUpContentView;
final RemoteViews publicContentView = entry.cachedPublicContentView;
if (contentView == null) {
Log.v(TAG, "no contentView for: " + sbn.getNotification());
return false;
}
if (DEBUG) {
Log.v(TAG, "publicContentView: " + publicContentView);
}
ExpandableNotificationRow row;
// Stash away previous user expansion state so we can restore it at
// the end.
boolean hasUserChangedExpansion = false;
boolean userExpanded = false;
boolean userLocked = false;
if (entry.row != null) {
row = entry.row;
hasUserChangedExpansion = row.hasUserChangedExpansion();
userExpanded = row.isUserExpanded();
userLocked = row.isUserLocked();
entry.reset();
if (hasUserChangedExpansion) {
row.setUserExpanded(userExpanded);
}
} else {
// create the row view
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// cannot use isMediaNotification()
if (sbn.getNotification().category != null && sbn.getNotification().category.equals(Notification.CATEGORY_TRANSPORT)) {
Log.d("ro", "inflating media notification");
row = (MediaExpandableNotificationRow) inflater.inflate(R.layout.status_bar_notification_row_media, parent, false);
((MediaExpandableNotificationRow) row).setMediaController(getCurrentMediaController());
} else {
row = (ExpandableNotificationRow) inflater.inflate(R.layout.status_bar_notification_row, parent, false);
}
row.setExpansionLogger(this, entry.notification.getKey());
row.setGroupManager(mGroupManager);
row.setHeadsUpManager(mHeadsUpManager);
row.setRemoteInputController(mRemoteInputController);
row.setOnExpandClickListener(this);
// Get the app name.
// Note that Notification.Builder#bindHeaderAppName has similar logic
// but since this field is used in the guts, it must be accurate.
// Therefore we will only show the application label, or, failing that, the
// package name. No substitutions.
final String pkg = sbn.getPackageName();
String appname = pkg;
try {
final ApplicationInfo info = pmUser.getApplicationInfo(pkg, PackageManager.GET_UNINSTALLED_PACKAGES | PackageManager.GET_DISABLED_COMPONENTS);
if (info != null) {
appname = String.valueOf(pmUser.getApplicationLabel(info));
}
} catch (NameNotFoundException e) {
// Do nothing
}
row.setAppName(appname);
}
workAroundBadLayerDrawableOpacity(row);
bindDismissListener(row);
// NB: the large icon is now handled entirely by the template
// bind the click event to the content area
NotificationContentView contentContainer = row.getPrivateLayout();
NotificationContentView contentContainerPublic = row.getPublicLayout();
row.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
if (ENABLE_REMOTE_INPUT) {
row.setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS);
}
mNotificationClicker.register(row, sbn);
// set up the adaptive layout
View contentViewLocal = null;
View bigContentViewLocal = null;
View headsUpContentViewLocal = null;
View publicViewLocal = null;
try {
contentViewLocal = contentView.apply(sbn.getPackageContext(mContext), contentContainer, mOnClickHandler);
if (bigContentView != null) {
bigContentViewLocal = bigContentView.apply(sbn.getPackageContext(mContext), contentContainer, mOnClickHandler);
}
if (headsUpContentView != null) {
headsUpContentViewLocal = headsUpContentView.apply(sbn.getPackageContext(mContext), contentContainer, mOnClickHandler);
}
if (publicContentView != null) {
publicViewLocal = publicContentView.apply(sbn.getPackageContext(mContext), contentContainerPublic, mOnClickHandler);
}
if (contentViewLocal != null) {
contentViewLocal.setIsRootNamespace(true);
contentContainer.setContractedChild(contentViewLocal);
}
if (bigContentViewLocal != null) {
bigContentViewLocal.setIsRootNamespace(true);
contentContainer.setExpandedChild(bigContentViewLocal);
}
if (headsUpContentViewLocal != null) {
headsUpContentViewLocal.setIsRootNamespace(true);
contentContainer.setHeadsUpChild(headsUpContentViewLocal);
}
if (publicViewLocal != null) {
publicViewLocal.setIsRootNamespace(true);
contentContainerPublic.setContractedChild(publicViewLocal);
}
} catch (RuntimeException e) {
final String ident = sbn.getPackageName() + "/0x" + Integer.toHexString(sbn.getId());
Log.e(TAG, "couldn't inflate view for notification " + ident, e);
return false;
}
// Extract target SDK version.
try {
ApplicationInfo info = pmUser.getApplicationInfo(sbn.getPackageName(), 0);
entry.targetSdk = info.targetSdkVersion;
} catch (NameNotFoundException ex) {
Log.e(TAG, "Failed looking up ApplicationInfo for " + sbn.getPackageName(), ex);
}
entry.autoRedacted = entry.notification.getNotification().publicVersion == null;
if (MULTIUSER_DEBUG) {
TextView debug = (TextView) row.findViewById(R.id.debug_info);
if (debug != null) {
debug.setVisibility(View.VISIBLE);
debug.setText("CU " + mCurrentUserId + " NU " + entry.notification.getUserId());
}
}
entry.row = row;
entry.row.setOnActivatedListener(this);
entry.row.setExpandable(bigContentViewLocal != null);
applyColorsAndBackgrounds(sbn, entry);
// Restore previous flags.
if (hasUserChangedExpansion) {
// Note: setUserExpanded() conveniently ignores calls with
// userExpanded=true if !isExpandable().
row.setUserExpanded(userExpanded);
}
row.setUserLocked(userLocked);
row.onNotificationUpdated(entry);
return true;
}
use of android.content.pm.ApplicationInfo in project android_frameworks_base by ResurrectionRemix.
the class AppOpsService method getOpsRawLocked.
private Ops getOpsRawLocked(int uid, String packageName, boolean edit) {
UidState uidState = getUidStateLocked(uid, edit);
if (uidState == null) {
return null;
}
if (uidState.pkgOps == null) {
if (!edit) {
return null;
}
uidState.pkgOps = new ArrayMap<>();
}
Ops ops = uidState.pkgOps.get(packageName);
if (ops == null) {
if (!edit) {
return null;
}
boolean isPrivileged = false;
// so let's make sure it is valid.
if (uid != 0) {
final long ident = Binder.clearCallingIdentity();
try {
int pkgUid = -1;
try {
ApplicationInfo appInfo = ActivityThread.getPackageManager().getApplicationInfo(packageName, PackageManager.MATCH_DEBUG_TRIAGED_MISSING, UserHandle.getUserId(uid));
if (appInfo != null) {
pkgUid = appInfo.uid;
isPrivileged = (appInfo.privateFlags & ApplicationInfo.PRIVATE_FLAG_PRIVILEGED) != 0;
} else {
if ("media".equals(packageName)) {
pkgUid = Process.MEDIA_UID;
isPrivileged = false;
} else if ("audioserver".equals(packageName)) {
pkgUid = Process.AUDIOSERVER_UID;
isPrivileged = false;
} else if ("cameraserver".equals(packageName)) {
pkgUid = Process.CAMERASERVER_UID;
isPrivileged = false;
}
}
} catch (RemoteException e) {
Slog.w(TAG, "Could not contact PackageManager", e);
}
if (pkgUid != uid) {
// Oops! The package name is not valid for the uid they are calling
// under. Abort.
RuntimeException ex = new RuntimeException("here");
ex.fillInStackTrace();
Slog.w(TAG, "Bad call: specified package " + packageName + " under uid " + uid + " but it is really " + pkgUid, ex);
return null;
}
} finally {
Binder.restoreCallingIdentity(ident);
}
}
ops = new Ops(packageName, uidState, isPrivileged);
uidState.pkgOps.put(packageName, ops);
}
return ops;
}
use of android.content.pm.ApplicationInfo in project android_frameworks_base by ResurrectionRemix.
the class AppOpsPolicy method getAppType.
private String getAppType(String packageName) {
String appType = null;
ApplicationInfo appInfo = null;
if (mContext != null) {
try {
appInfo = mContext.getPackageManager().getApplicationInfo(packageName, 0);
} catch (NameNotFoundException e) {
appInfo = null;
}
if (appInfo != null) {
if ((appInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
appType = "system-app";
} else {
appType = "user-app";
}
}
} else {
Slog.e(TAG, "Context is null");
}
return appType;
}
use of android.content.pm.ApplicationInfo in project android_frameworks_base by ResurrectionRemix.
the class AppOpsService method readUid.
void readUid(XmlPullParser parser, String pkgName) throws NumberFormatException, XmlPullParserException, IOException {
int uid = Integer.parseInt(parser.getAttributeValue(null, "n"));
String isPrivilegedString = parser.getAttributeValue(null, "p");
boolean isPrivileged = false;
if (isPrivilegedString == null) {
try {
IPackageManager packageManager = ActivityThread.getPackageManager();
if (packageManager != null) {
ApplicationInfo appInfo = ActivityThread.getPackageManager().getApplicationInfo(pkgName, 0, UserHandle.getUserId(uid));
if (appInfo != null) {
isPrivileged = (appInfo.privateFlags & ApplicationInfo.PRIVATE_FLAG_PRIVILEGED) != 0;
}
} else {
// Could not load data, don't add to cache so it will be loaded later.
return;
}
} catch (RemoteException e) {
Slog.w(TAG, "Could not contact PackageManager", e);
}
} else {
isPrivileged = Boolean.parseBoolean(isPrivilegedString);
}
int outerDepth = parser.getDepth();
int type;
while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
continue;
}
String tagName = parser.getName();
if (tagName.equals("op")) {
int code = Integer.parseInt(parser.getAttributeValue(null, "n"));
// use op name string if it exists
String codeNameStr = parser.getAttributeValue(null, "ns");
if (codeNameStr != null) {
// returns OP_NONE if it could not be mapped
code = AppOpsManager.nameToOp(codeNameStr);
}
// skip op codes that are out of bounds
if (code == AppOpsManager.OP_NONE || code >= AppOpsManager._NUM_OP) {
continue;
}
Op op = new Op(uid, pkgName, code, AppOpsManager.MODE_ERRORED);
String mode = parser.getAttributeValue(null, "m");
if (mode != null) {
op.mode = Integer.parseInt(mode);
} else {
String sDefualtMode = parser.getAttributeValue(null, "dm");
int defaultMode;
if (sDefualtMode != null) {
defaultMode = Integer.parseInt(sDefualtMode);
} else {
defaultMode = getDefaultMode(code, uid, pkgName);
}
op.mode = defaultMode;
}
String time = parser.getAttributeValue(null, "t");
if (time != null) {
op.time = Long.parseLong(time);
}
time = parser.getAttributeValue(null, "r");
if (time != null) {
op.rejectTime = Long.parseLong(time);
}
String dur = parser.getAttributeValue(null, "d");
if (dur != null) {
op.duration = Integer.parseInt(dur);
}
String proxyUid = parser.getAttributeValue(null, "pu");
if (proxyUid != null) {
op.proxyUid = Integer.parseInt(proxyUid);
}
String proxyPackageName = parser.getAttributeValue(null, "pp");
if (proxyPackageName != null) {
op.proxyPackageName = proxyPackageName;
}
String allowed = parser.getAttributeValue(null, "ac");
if (allowed != null) {
op.allowedCount = Integer.parseInt(allowed);
}
String ignored = parser.getAttributeValue(null, "ic");
if (ignored != null) {
op.ignoredCount = Integer.parseInt(ignored);
}
UidState uidState = getUidStateLocked(uid, true);
if (uidState.pkgOps == null) {
uidState.pkgOps = new ArrayMap<>();
}
Ops ops = uidState.pkgOps.get(pkgName);
if (ops == null) {
ops = new Ops(pkgName, uidState, isPrivileged);
uidState.pkgOps.put(pkgName, ops);
}
ops.put(op.op, op);
} else {
Slog.w(TAG, "Unknown element under <pkg>: " + parser.getName());
XmlUtils.skipCurrentTag(parser);
}
}
}
use of android.content.pm.ApplicationInfo in project android_frameworks_base by ResurrectionRemix.
the class TaskRecord method restoreFromXml.
static TaskRecord restoreFromXml(XmlPullParser in, ActivityStackSupervisor stackSupervisor) throws IOException, XmlPullParserException {
Intent intent = null;
Intent affinityIntent = null;
ArrayList<ActivityRecord> activities = new ArrayList<>();
ComponentName realActivity = null;
boolean realActivitySuspended = false;
ComponentName origActivity = null;
String affinity = null;
String rootAffinity = null;
boolean hasRootAffinity = false;
boolean rootHasReset = false;
boolean autoRemoveRecents = false;
boolean askedCompatMode = false;
int taskType = ActivityRecord.APPLICATION_ACTIVITY_TYPE;
int userId = 0;
boolean userSetupComplete = true;
int effectiveUid = -1;
String lastDescription = null;
long firstActiveTime = -1;
long lastActiveTime = -1;
long lastTimeOnTop = 0;
boolean neverRelinquishIdentity = true;
int taskId = INVALID_TASK_ID;
final int outerDepth = in.getDepth();
TaskDescription taskDescription = new TaskDescription();
TaskThumbnailInfo thumbnailInfo = new TaskThumbnailInfo();
int taskAffiliation = INVALID_TASK_ID;
int taskAffiliationColor = 0;
int prevTaskId = INVALID_TASK_ID;
int nextTaskId = INVALID_TASK_ID;
int callingUid = -1;
String callingPackage = "";
int resizeMode = RESIZE_MODE_FORCE_RESIZEABLE;
boolean privileged = false;
Rect bounds = null;
int minWidth = INVALID_MIN_SIZE;
int minHeight = INVALID_MIN_SIZE;
for (int attrNdx = in.getAttributeCount() - 1; attrNdx >= 0; --attrNdx) {
final String attrName = in.getAttributeName(attrNdx);
final String attrValue = in.getAttributeValue(attrNdx);
if (TaskPersister.DEBUG)
Slog.d(TaskPersister.TAG, "TaskRecord: attribute name=" + attrName + " value=" + attrValue);
if (ATTR_TASKID.equals(attrName)) {
if (taskId == INVALID_TASK_ID)
taskId = Integer.parseInt(attrValue);
} else if (ATTR_REALACTIVITY.equals(attrName)) {
realActivity = ComponentName.unflattenFromString(attrValue);
} else if (ATTR_REALACTIVITY_SUSPENDED.equals(attrName)) {
realActivitySuspended = Boolean.valueOf(attrValue);
} else if (ATTR_ORIGACTIVITY.equals(attrName)) {
origActivity = ComponentName.unflattenFromString(attrValue);
} else if (ATTR_AFFINITY.equals(attrName)) {
affinity = attrValue;
} else if (ATTR_ROOT_AFFINITY.equals(attrName)) {
rootAffinity = attrValue;
hasRootAffinity = true;
} else if (ATTR_ROOTHASRESET.equals(attrName)) {
rootHasReset = Boolean.valueOf(attrValue);
} else if (ATTR_AUTOREMOVERECENTS.equals(attrName)) {
autoRemoveRecents = Boolean.valueOf(attrValue);
} else if (ATTR_ASKEDCOMPATMODE.equals(attrName)) {
askedCompatMode = Boolean.valueOf(attrValue);
} else if (ATTR_USERID.equals(attrName)) {
userId = Integer.parseInt(attrValue);
} else if (ATTR_USER_SETUP_COMPLETE.equals(attrName)) {
userSetupComplete = Boolean.valueOf(attrValue);
} else if (ATTR_EFFECTIVE_UID.equals(attrName)) {
effectiveUid = Integer.parseInt(attrValue);
} else if (ATTR_TASKTYPE.equals(attrName)) {
taskType = Integer.parseInt(attrValue);
} else if (ATTR_FIRSTACTIVETIME.equals(attrName)) {
firstActiveTime = Long.valueOf(attrValue);
} else if (ATTR_LASTACTIVETIME.equals(attrName)) {
lastActiveTime = Long.valueOf(attrValue);
} else if (ATTR_LASTDESCRIPTION.equals(attrName)) {
lastDescription = attrValue;
} else if (ATTR_LASTTIMEMOVED.equals(attrName)) {
lastTimeOnTop = Long.valueOf(attrValue);
} else if (ATTR_NEVERRELINQUISH.equals(attrName)) {
neverRelinquishIdentity = Boolean.valueOf(attrValue);
} else if (attrName.startsWith(TaskThumbnailInfo.ATTR_TASK_THUMBNAILINFO_PREFIX)) {
thumbnailInfo.restoreFromXml(attrName, attrValue);
} else if (attrName.startsWith(TaskDescription.ATTR_TASKDESCRIPTION_PREFIX)) {
taskDescription.restoreFromXml(attrName, attrValue);
} else if (ATTR_TASK_AFFILIATION.equals(attrName)) {
taskAffiliation = Integer.parseInt(attrValue);
} else if (ATTR_PREV_AFFILIATION.equals(attrName)) {
prevTaskId = Integer.parseInt(attrValue);
} else if (ATTR_NEXT_AFFILIATION.equals(attrName)) {
nextTaskId = Integer.parseInt(attrValue);
} else if (ATTR_TASK_AFFILIATION_COLOR.equals(attrName)) {
taskAffiliationColor = Integer.parseInt(attrValue);
} else if (ATTR_CALLING_UID.equals(attrName)) {
callingUid = Integer.parseInt(attrValue);
} else if (ATTR_CALLING_PACKAGE.equals(attrName)) {
callingPackage = attrValue;
} else if (ATTR_RESIZE_MODE.equals(attrName)) {
resizeMode = Integer.parseInt(attrValue);
resizeMode = (resizeMode == RESIZE_MODE_CROP_WINDOWS) ? RESIZE_MODE_FORCE_RESIZEABLE : resizeMode;
} else if (ATTR_PRIVILEGED.equals(attrName)) {
privileged = Boolean.valueOf(attrValue);
} else if (ATTR_NON_FULLSCREEN_BOUNDS.equals(attrName)) {
bounds = Rect.unflattenFromString(attrValue);
} else if (ATTR_MIN_WIDTH.equals(attrName)) {
minWidth = Integer.parseInt(attrValue);
} else if (ATTR_MIN_HEIGHT.equals(attrName)) {
minHeight = Integer.parseInt(attrValue);
} else {
Slog.w(TAG, "TaskRecord: Unknown attribute=" + attrName);
}
}
int event;
while (((event = in.next()) != XmlPullParser.END_DOCUMENT) && (event != XmlPullParser.END_TAG || in.getDepth() >= outerDepth)) {
if (event == XmlPullParser.START_TAG) {
final String name = in.getName();
if (TaskPersister.DEBUG)
Slog.d(TaskPersister.TAG, "TaskRecord: START_TAG name=" + name);
if (TAG_AFFINITYINTENT.equals(name)) {
affinityIntent = Intent.restoreFromXml(in);
} else if (TAG_INTENT.equals(name)) {
intent = Intent.restoreFromXml(in);
} else if (TAG_ACTIVITY.equals(name)) {
ActivityRecord activity = ActivityRecord.restoreFromXml(in, stackSupervisor);
if (TaskPersister.DEBUG)
Slog.d(TaskPersister.TAG, "TaskRecord: activity=" + activity);
if (activity != null) {
activities.add(activity);
}
} else {
Slog.e(TAG, "restoreTask: Unexpected name=" + name);
XmlUtils.skipCurrentTag(in);
}
}
}
if (!hasRootAffinity) {
rootAffinity = affinity;
} else if ("@".equals(rootAffinity)) {
rootAffinity = null;
}
if (effectiveUid <= 0) {
Intent checkIntent = intent != null ? intent : affinityIntent;
effectiveUid = 0;
if (checkIntent != null) {
IPackageManager pm = AppGlobals.getPackageManager();
try {
ApplicationInfo ai = pm.getApplicationInfo(checkIntent.getComponent().getPackageName(), PackageManager.GET_UNINSTALLED_PACKAGES | PackageManager.GET_DISABLED_COMPONENTS, userId);
if (ai != null) {
effectiveUid = ai.uid;
}
} catch (RemoteException e) {
}
}
Slog.w(TAG, "Updating task #" + taskId + " for " + checkIntent + ": effectiveUid=" + effectiveUid);
}
final TaskRecord task = new TaskRecord(stackSupervisor.mService, taskId, intent, affinityIntent, affinity, rootAffinity, realActivity, origActivity, rootHasReset, autoRemoveRecents, askedCompatMode, taskType, userId, effectiveUid, lastDescription, activities, firstActiveTime, lastActiveTime, lastTimeOnTop, neverRelinquishIdentity, taskDescription, thumbnailInfo, taskAffiliation, prevTaskId, nextTaskId, taskAffiliationColor, callingUid, callingPackage, resizeMode, privileged, realActivitySuspended, userSetupComplete, minWidth, minHeight);
task.updateOverrideConfiguration(bounds);
for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) {
activities.get(activityNdx).task = task;
}
if (DEBUG_RECENTS)
Slog.d(TAG_RECENTS, "Restored task=" + task);
return task;
}
Aggregations