Search in sources :

Example 46 with ApplicationInfo

use of android.content.pm.ApplicationInfo in project android_frameworks_base by ResurrectionRemix.

the class BatteryStatsService method dump.

@Override
protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
    if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) != PackageManager.PERMISSION_GRANTED) {
        pw.println("Permission Denial: can't dump BatteryStats from from pid=" + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid() + " without permission " + android.Manifest.permission.DUMP);
        return;
    }
    int flags = 0;
    boolean useCheckinFormat = false;
    boolean isRealCheckin = false;
    boolean noOutput = false;
    boolean writeData = false;
    long historyStart = -1;
    int reqUid = -1;
    if (args != null) {
        for (int i = 0; i < args.length; i++) {
            String arg = args[i];
            if ("--checkin".equals(arg)) {
                useCheckinFormat = true;
                isRealCheckin = true;
            } else if ("--history".equals(arg)) {
                flags |= BatteryStats.DUMP_HISTORY_ONLY;
            } else if ("--history-start".equals(arg)) {
                flags |= BatteryStats.DUMP_HISTORY_ONLY;
                i++;
                if (i >= args.length) {
                    pw.println("Missing time argument for --history-since");
                    dumpHelp(pw);
                    return;
                }
                historyStart = Long.parseLong(args[i]);
                writeData = true;
            } else if ("-c".equals(arg)) {
                useCheckinFormat = true;
                flags |= BatteryStats.DUMP_INCLUDE_HISTORY;
            } else if ("--charged".equals(arg)) {
                flags |= BatteryStats.DUMP_CHARGED_ONLY;
            } else if ("--daily".equals(arg)) {
                flags |= BatteryStats.DUMP_DAILY_ONLY;
            } else if ("--reset".equals(arg)) {
                synchronized (mStats) {
                    mStats.resetAllStatsCmdLocked();
                    pw.println("Battery stats reset.");
                    noOutput = true;
                }
                updateExternalStatsSync("dump", BatteryStatsImpl.ExternalStatsSync.UPDATE_ALL);
            } else if ("--write".equals(arg)) {
                updateExternalStatsSync("dump", BatteryStatsImpl.ExternalStatsSync.UPDATE_ALL);
                synchronized (mStats) {
                    mStats.writeSyncLocked();
                    pw.println("Battery stats written.");
                    noOutput = true;
                }
            } else if ("--new-daily".equals(arg)) {
                synchronized (mStats) {
                    mStats.recordDailyStatsLocked();
                    pw.println("New daily stats written.");
                    noOutput = true;
                }
            } else if ("--read-daily".equals(arg)) {
                synchronized (mStats) {
                    mStats.readDailyStatsLocked();
                    pw.println("Last daily stats read.");
                    noOutput = true;
                }
            } else if ("--enable".equals(arg) || "enable".equals(arg)) {
                i = doEnableOrDisable(pw, i, args, true);
                if (i < 0) {
                    return;
                }
                pw.println("Enabled: " + args[i]);
                return;
            } else if ("--disable".equals(arg) || "disable".equals(arg)) {
                i = doEnableOrDisable(pw, i, args, false);
                if (i < 0) {
                    return;
                }
                pw.println("Disabled: " + args[i]);
                return;
            } else if ("-h".equals(arg)) {
                dumpHelp(pw);
                return;
            } else if ("-a".equals(arg)) {
                flags |= BatteryStats.DUMP_VERBOSE;
            } else if (arg.length() > 0 && arg.charAt(0) == '-') {
                pw.println("Unknown option: " + arg);
                dumpHelp(pw);
                return;
            } else {
                // Not an option, last argument must be a package name.
                try {
                    reqUid = mContext.getPackageManager().getPackageUidAsUser(arg, UserHandle.getCallingUserId());
                } catch (PackageManager.NameNotFoundException e) {
                    pw.println("Unknown package: " + arg);
                    dumpHelp(pw);
                    return;
                }
            }
        }
    }
    if (noOutput) {
        return;
    }
    long ident = Binder.clearCallingIdentity();
    try {
        if (BatteryStatsHelper.checkWifiOnly(mContext)) {
            flags |= BatteryStats.DUMP_DEVICE_WIFI_ONLY;
        }
        // Fetch data from external sources and update the BatteryStatsImpl object with them.
        updateExternalStatsSync("dump", BatteryStatsImpl.ExternalStatsSync.UPDATE_ALL);
    } finally {
        Binder.restoreCallingIdentity(ident);
    }
    if (reqUid >= 0) {
        // we only dump the aggregated data since charged.
        if ((flags & (BatteryStats.DUMP_HISTORY_ONLY | BatteryStats.DUMP_CHARGED_ONLY)) == 0) {
            flags |= BatteryStats.DUMP_CHARGED_ONLY;
            // Also if they are doing -c, we don't want history.
            flags &= ~BatteryStats.DUMP_INCLUDE_HISTORY;
        }
    }
    if (useCheckinFormat) {
        List<ApplicationInfo> apps = mContext.getPackageManager().getInstalledApplications(PackageManager.MATCH_UNINSTALLED_PACKAGES | PackageManager.MATCH_ALL);
        if (isRealCheckin) {
            // file if there is one.
            synchronized (mStats.mCheckinFile) {
                if (mStats.mCheckinFile.exists()) {
                    try {
                        byte[] raw = mStats.mCheckinFile.readFully();
                        if (raw != null) {
                            Parcel in = Parcel.obtain();
                            in.unmarshall(raw, 0, raw.length);
                            in.setDataPosition(0);
                            BatteryStatsImpl checkinStats = new BatteryStatsImpl(null, mStats.mHandler, null);
                            checkinStats.readSummaryFromParcel(in);
                            in.recycle();
                            checkinStats.dumpCheckinLocked(mContext, pw, apps, flags, historyStart);
                            mStats.mCheckinFile.delete();
                            return;
                        }
                    } catch (IOException | ParcelFormatException e) {
                        Slog.w(TAG, "Failure reading checkin file " + mStats.mCheckinFile.getBaseFile(), e);
                    }
                }
            }
        }
        synchronized (mStats) {
            mStats.dumpCheckinLocked(mContext, pw, apps, flags, historyStart);
            if (writeData) {
                mStats.writeAsyncLocked();
            }
        }
    } else {
        synchronized (mStats) {
            mStats.dumpLocked(mContext, pw, flags, reqUid, historyStart);
            if (writeData) {
                mStats.writeAsyncLocked();
            }
        }
    }
}
Also used : ParcelFormatException(android.os.ParcelFormatException) Parcel(android.os.Parcel) ApplicationInfo(android.content.pm.ApplicationInfo) IOException(java.io.IOException) BatteryStatsImpl(com.android.internal.os.BatteryStatsImpl) PackageManager(android.content.pm.PackageManager)

Example 47 with ApplicationInfo

use of android.content.pm.ApplicationInfo in project android_frameworks_base by ResurrectionRemix.

the class CompatModePackages method setPackageScreenCompatModeLocked.

public void setPackageScreenCompatModeLocked(String packageName, int mode) {
    ApplicationInfo ai = null;
    try {
        ai = AppGlobals.getPackageManager().getApplicationInfo(packageName, 0, 0);
    } catch (RemoteException e) {
    }
    if (ai == null) {
        Slog.w(TAG, "setPackageScreenCompatMode failed: unknown package " + packageName);
        return;
    }
    setPackageScreenCompatModeLocked(ai, mode);
}
Also used : ApplicationInfo(android.content.pm.ApplicationInfo) RemoteException(android.os.RemoteException)

Example 48 with ApplicationInfo

use of android.content.pm.ApplicationInfo in project android_frameworks_base by ResurrectionRemix.

the class CompatModePackages method saveCompatModes.

void saveCompatModes() {
    HashMap<String, Integer> pkgs;
    synchronized (mService) {
        pkgs = new HashMap<String, Integer>(mPackages);
    }
    FileOutputStream fos = null;
    try {
        fos = mFile.startWrite();
        XmlSerializer out = new FastXmlSerializer();
        out.setOutput(fos, StandardCharsets.UTF_8.name());
        out.startDocument(null, true);
        out.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
        out.startTag(null, "compat-packages");
        final IPackageManager pm = AppGlobals.getPackageManager();
        final int screenLayout = mService.mConfiguration.screenLayout;
        final int smallestScreenWidthDp = mService.mConfiguration.smallestScreenWidthDp;
        final Iterator<Map.Entry<String, Integer>> it = pkgs.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry<String, Integer> entry = it.next();
            String pkg = entry.getKey();
            int mode = entry.getValue();
            if (mode == 0) {
                continue;
            }
            ApplicationInfo ai = null;
            try {
                ai = pm.getApplicationInfo(pkg, 0, 0);
            } catch (RemoteException e) {
            }
            if (ai == null) {
                continue;
            }
            CompatibilityInfo info = new CompatibilityInfo(ai, screenLayout, smallestScreenWidthDp, false);
            if (info.alwaysSupportsScreen()) {
                continue;
            }
            if (info.neverSupportsScreen()) {
                continue;
            }
            out.startTag(null, "pkg");
            out.attribute(null, "name", pkg);
            out.attribute(null, "mode", Integer.toString(mode));
            out.endTag(null, "pkg");
        }
        out.endTag(null, "compat-packages");
        out.endDocument();
        mFile.finishWrite(fos);
    } catch (java.io.IOException e1) {
        Slog.w(TAG, "Error writing compat packages", e1);
        if (fos != null) {
            mFile.failWrite(fos);
        }
    }
}
Also used : ApplicationInfo(android.content.pm.ApplicationInfo) CompatibilityInfo(android.content.res.CompatibilityInfo) FastXmlSerializer(com.android.internal.util.FastXmlSerializer) IPackageManager(android.content.pm.IPackageManager) FileOutputStream(java.io.FileOutputStream) RemoteException(android.os.RemoteException) HashMap(java.util.HashMap) Map(java.util.Map) XmlSerializer(org.xmlpull.v1.XmlSerializer) FastXmlSerializer(com.android.internal.util.FastXmlSerializer)

Example 49 with ApplicationInfo

use of android.content.pm.ApplicationInfo in project android_frameworks_base by ResurrectionRemix.

the class AppPickerAdapter method getView.

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View view = convertView;
    if (null == view) {
        LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = layoutInflater.inflate(R.layout.app_picker_list_item, null);
    }
    ApplicationInfo data = appList.get(position);
    if (null != data) {
        TextView appName = (TextView) view.findViewById(R.id.app_name);
        TextView packageName = (TextView) view.findViewById(R.id.app_package);
        ImageView iconView = (ImageView) view.findViewById(R.id.app_icon);
        appName.setText(data.loadLabel(packageManager));
        packageName.setText(data.packageName);
        iconView.setImageDrawable(data.loadIcon(packageManager));
    }
    return view;
}
Also used : LayoutInflater(android.view.LayoutInflater) ApplicationInfo(android.content.pm.ApplicationInfo) TextView(android.widget.TextView) ImageView(android.widget.ImageView) TextView(android.widget.TextView) ImageView(android.widget.ImageView) View(android.view.View)

Example 50 with ApplicationInfo

use of android.content.pm.ApplicationInfo in project android_frameworks_base by ResurrectionRemix.

the class BaseShortcutManagerTest method genPackage.

protected PackageInfo genPackage(String packageName, int uid, int version, String... signatures) {
    final PackageInfo pi = new PackageInfo();
    pi.packageName = packageName;
    pi.applicationInfo = new ApplicationInfo();
    pi.applicationInfo.uid = uid;
    pi.applicationInfo.flags = ApplicationInfo.FLAG_INSTALLED | ApplicationInfo.FLAG_ALLOW_BACKUP;
    pi.versionCode = version;
    pi.applicationInfo.versionCode = version;
    pi.signatures = genSignatures(signatures);
    return pi;
}
Also used : PackageInfo(android.content.pm.PackageInfo) ApplicationInfo(android.content.pm.ApplicationInfo)

Aggregations

ApplicationInfo (android.content.pm.ApplicationInfo)1914 PackageManager (android.content.pm.PackageManager)682 Test (org.junit.Test)366 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)363 ArrayList (java.util.ArrayList)258 Intent (android.content.Intent)231 RemoteException (android.os.RemoteException)229 PackageInfo (android.content.pm.PackageInfo)214 ResolveInfo (android.content.pm.ResolveInfo)177 IOException (java.io.IOException)122 ActivityInfo (android.content.pm.ActivityInfo)114 IPackageManager (android.content.pm.IPackageManager)109 UserHandle (android.os.UserHandle)108 Context (android.content.Context)103 Bundle (android.os.Bundle)103 File (java.io.File)100 Drawable (android.graphics.drawable.Drawable)91 UserInfo (android.content.pm.UserInfo)89 ComponentName (android.content.ComponentName)69 SmallTest (android.support.test.filters.SmallTest)66