Example usage for android.util Slog i

List of usage examples for android.util Slog i

Introduction

In this page you can find the example usage for android.util Slog i.

Prototype

@UnsupportedAppUsage
    public static int i(String tag, String msg) 

Source Link

Usage

From source file:com.android.server.MountService.java

/**
 * Callback from NativeDaemonConnector//from  w ww  .j a  va2 s. c  om
 */
public void onDaemonConnected() {
    /*
     * Since we'll be calling back into the NativeDaemonConnector,
     * we need to do our work in a new thread.
     */
    new Thread("MountService#onDaemonConnected") {
        @Override
        public void run() {
            /**
             * Determine media state and UMS detection status
             */
            try {
                final String[] vols = NativeDaemonEvent.filterMessageList(
                        mConnector.executeForList("volume", "list", "broadcast"),
                        VoldResponseCode.VolumeListResult);
                for (String volstr : vols) {
                    String[] tok = volstr.split(" ");
                    // FMT: <label> <mountpoint> <state>
                    String path = tok[1];
                    String state = Environment.MEDIA_REMOVED;

                    final StorageVolume volume;
                    synchronized (mVolumesLock) {
                        volume = mVolumesByPath.get(path);
                    }

                    int st = Integer.parseInt(tok[2]);
                    if (st == VolumeState.NoMedia) {
                        state = Environment.MEDIA_REMOVED;
                    } else if (st == VolumeState.Idle) {
                        state = Environment.MEDIA_UNMOUNTED;
                    } else if (st == VolumeState.Mounted) {
                        state = Environment.MEDIA_MOUNTED;
                        Slog.i(TAG, "Media already mounted on daemon connection");
                    } else if (st == VolumeState.Shared) {
                        state = Environment.MEDIA_SHARED;
                        Slog.i(TAG, "Media shared on daemon connection");
                    } else {
                        throw new Exception(String.format("Unexpected state %d", st));
                    }

                    if (state != null) {
                        if (DEBUG_EVENTS)
                            Slog.i(TAG, "Updating valid state " + state);
                        updatePublicVolumeState(volume, state);
                    }
                }
            } catch (Exception e) {
                Slog.e(TAG, "Error processing initial volume state", e);
                final StorageVolume primary = getPrimaryPhysicalVolume();
                if (primary != null) {
                    updatePublicVolumeState(primary, Environment.MEDIA_REMOVED);
                }
            }

            /*
             * Now that we've done our initialization, release
             * the hounds!
             */
            mConnectedSignal.countDown();

            // On an encrypted device we can't see system properties yet, so pull
            // the system locale out of the mount service.
            if ("".equals(SystemProperties.get("vold.encrypt_progress"))) {
                copyLocaleFromMountService();
            }

            // Let package manager load internal ASECs.
            mPms.scanAvailableAsecs();

            // Notify people waiting for ASECs to be scanned that it's done.
            mAsecsScanned.countDown();
        }
    }.start();
}

From source file:com.android.server.MountService.java

/**
 * Callback from NativeDaemonConnector//  w ww .j a  v  a2 s.  co  m
 */
public boolean onEvent(int code, String raw, String[] cooked) {
    if (DEBUG_EVENTS) {
        StringBuilder builder = new StringBuilder();
        builder.append("onEvent::");
        builder.append(" raw= " + raw);
        if (cooked != null) {
            builder.append(" cooked = ");
            for (String str : cooked) {
                builder.append(" " + str);
            }
        }
        Slog.i(TAG, builder.toString());
    }
    if (code == VoldResponseCode.VolumeStateChange) {
        /*
         * One of the volumes we're managing has changed state.
         * Format: "NNN Volume <label> <path> state changed
         * from <old_#> (<old_str>) to <new_#> (<new_str>)"
         */
        notifyVolumeStateChange(cooked[2], cooked[3], Integer.parseInt(cooked[7]),
                Integer.parseInt(cooked[10]));
    } else if (code == VoldResponseCode.VolumeUuidChange) {
        // Format: nnn <label> <path> <uuid>
        final String path = cooked[2];
        final String uuid = (cooked.length > 3) ? cooked[3] : null;

        final StorageVolume vol = mVolumesByPath.get(path);
        if (vol != null) {
            vol.setUuid(uuid);
        }

    } else if (code == VoldResponseCode.VolumeUserLabelChange) {
        // Format: nnn <label> <path> <label>
        final String path = cooked[2];
        final String userLabel = (cooked.length > 3) ? cooked[3] : null;

        final StorageVolume vol = mVolumesByPath.get(path);
        if (vol != null) {
            vol.setUserLabel(userLabel);
        }

    } else if ((code == VoldResponseCode.VolumeDiskInserted) || (code == VoldResponseCode.VolumeDiskRemoved)
            || (code == VoldResponseCode.VolumeBadRemoval)) {
        // FMT: NNN Volume <label> <mountpoint> disk inserted (<major>:<minor>)
        // FMT: NNN Volume <label> <mountpoint> disk removed (<major>:<minor>)
        // FMT: NNN Volume <label> <mountpoint> bad removal (<major>:<minor>)
        String action = null;
        final String label = cooked[2];
        final String path = cooked[3];
        int major = -1;
        int minor = -1;

        try {
            String devComp = cooked[6].substring(1, cooked[6].length() - 1);
            String[] devTok = devComp.split(":");
            major = Integer.parseInt(devTok[0]);
            minor = Integer.parseInt(devTok[1]);
        } catch (Exception ex) {
            Slog.e(TAG, "Failed to parse major/minor", ex);
        }

        final StorageVolume volume;
        final String state;
        synchronized (mVolumesLock) {
            volume = mVolumesByPath.get(path);
            state = mVolumeStates.get(path);
        }

        if (code == VoldResponseCode.VolumeDiskInserted) {
            new Thread("MountService#VolumeDiskInserted") {
                @Override
                public void run() {
                    try {
                        int rc;
                        if ((rc = doMountVolume(path)) != StorageResultCode.OperationSucceeded) {
                            Slog.w(TAG, String.format("Insertion mount failed (%d)", rc));
                        }
                    } catch (Exception ex) {
                        Slog.w(TAG, "Failed to mount media on insertion", ex);
                    }
                }
            }.start();
        } else if (code == VoldResponseCode.VolumeDiskRemoved) {
            /*
             * This event gets trumped if we're already in BAD_REMOVAL state
             */
            if (getVolumeState(path).equals(Environment.MEDIA_BAD_REMOVAL)) {
                return true;
            }
            /* Send the media unmounted event first */
            if (DEBUG_EVENTS)
                Slog.i(TAG, "Sending unmounted event first");
            updatePublicVolumeState(volume, Environment.MEDIA_UNMOUNTED);
            sendStorageIntent(Intent.ACTION_MEDIA_UNMOUNTED, volume, UserHandle.ALL);

            if (DEBUG_EVENTS)
                Slog.i(TAG, "Sending media removed");
            updatePublicVolumeState(volume, Environment.MEDIA_REMOVED);
            action = Intent.ACTION_MEDIA_REMOVED;
        } else if (code == VoldResponseCode.VolumeBadRemoval) {
            if (DEBUG_EVENTS)
                Slog.i(TAG, "Sending unmounted event first");
            /* Send the media unmounted event first */
            updatePublicVolumeState(volume, Environment.MEDIA_UNMOUNTED);
            sendStorageIntent(Intent.ACTION_MEDIA_UNMOUNTED, volume, UserHandle.ALL);

            if (DEBUG_EVENTS)
                Slog.i(TAG, "Sending media bad removal");
            updatePublicVolumeState(volume, Environment.MEDIA_BAD_REMOVAL);
            action = Intent.ACTION_MEDIA_BAD_REMOVAL;
        } else if (code == VoldResponseCode.FstrimCompleted) {
            EventLogTags.writeFstrimFinish(SystemClock.elapsedRealtime());
        } else {
            Slog.e(TAG, String.format("Unknown code {%d}", code));
        }

        if (action != null) {
            sendStorageIntent(action, volume, UserHandle.ALL);
        }
    } else {
        return false;
    }

    return true;
}

From source file:com.android.server.MountService.java

private void notifyVolumeStateChange(String label, String path, int oldState, int newState) {
    final StorageVolume volume;
    final String state;
    synchronized (mVolumesLock) {
        volume = mVolumesByPath.get(path);
        state = getVolumeState(path);//from w w w.  j a  v  a  2 s  . co  m
    }

    if (DEBUG_EVENTS)
        Slog.i(TAG, "notifyVolumeStateChange::" + state);

    String action = null;

    if (oldState == VolumeState.Shared && newState != oldState) {
        if (LOCAL_LOGD)
            Slog.d(TAG, "Sending ACTION_MEDIA_UNSHARED intent");
        sendStorageIntent(Intent.ACTION_MEDIA_UNSHARED, volume, UserHandle.ALL);
    }

    if (newState == VolumeState.Init) {
    } else if (newState == VolumeState.NoMedia) {
        // NoMedia is handled via Disk Remove events
    } else if (newState == VolumeState.Idle) {
        /*
         * Don't notify if we're in BAD_REMOVAL, NOFS, UNMOUNTABLE, or
         * if we're in the process of enabling UMS
         */
        if (!state.equals(Environment.MEDIA_BAD_REMOVAL) && !state.equals(Environment.MEDIA_NOFS)
                && !state.equals(Environment.MEDIA_UNMOUNTABLE) && !getUmsEnabling()) {
            if (DEBUG_EVENTS)
                Slog.i(TAG, "updating volume state for media bad removal nofs and unmountable");
            updatePublicVolumeState(volume, Environment.MEDIA_UNMOUNTED);
            action = Intent.ACTION_MEDIA_UNMOUNTED;
        }
    } else if (newState == VolumeState.Pending) {
    } else if (newState == VolumeState.Checking) {
        if (DEBUG_EVENTS)
            Slog.i(TAG, "updating volume state checking");
        updatePublicVolumeState(volume, Environment.MEDIA_CHECKING);
        action = Intent.ACTION_MEDIA_CHECKING;
    } else if (newState == VolumeState.Mounted) {
        if (DEBUG_EVENTS)
            Slog.i(TAG, "updating volume state mounted");
        updatePublicVolumeState(volume, Environment.MEDIA_MOUNTED);
        action = Intent.ACTION_MEDIA_MOUNTED;
    } else if (newState == VolumeState.Unmounting) {
        action = Intent.ACTION_MEDIA_EJECT;
    } else if (newState == VolumeState.Formatting) {
    } else if (newState == VolumeState.Shared) {
        if (DEBUG_EVENTS)
            Slog.i(TAG, "Updating volume state media mounted");
        /* Send the media unmounted event first */
        updatePublicVolumeState(volume, Environment.MEDIA_UNMOUNTED);
        sendStorageIntent(Intent.ACTION_MEDIA_UNMOUNTED, volume, UserHandle.ALL);

        if (DEBUG_EVENTS)
            Slog.i(TAG, "Updating media shared");
        updatePublicVolumeState(volume, Environment.MEDIA_SHARED);
        action = Intent.ACTION_MEDIA_SHARED;
        if (LOCAL_LOGD)
            Slog.d(TAG, "Sending ACTION_MEDIA_SHARED intent");
    } else if (newState == VolumeState.SharedMnt) {
        Slog.e(TAG, "Live shared mounts not supported yet!");
        return;
    } else {
        Slog.e(TAG, "Unhandled VolumeState {" + newState + "}");
    }

    if (action != null) {
        sendStorageIntent(action, volume, UserHandle.ALL);
    }
}

From source file:com.android.server.MountService.java

private int doMountVolume(String path) {
    int rc = StorageResultCode.OperationSucceeded;

    final StorageVolume volume;
    synchronized (mVolumesLock) {
        volume = mVolumesByPath.get(path);
    }/*  w  ww .ja  va 2 s .com*/

    if (!volume.isEmulated() && hasUserRestriction(UserManager.DISALLOW_MOUNT_PHYSICAL_MEDIA)) {
        Slog.w(TAG, "User has restriction DISALLOW_MOUNT_PHYSICAL_MEDIA; cannot mount volume.");
        return StorageResultCode.OperationFailedInternalError;
    }

    if (DEBUG_EVENTS)
        Slog.i(TAG, "doMountVolume: Mouting " + path);
    try {
        mConnector.execute("volume", "mount", path);
    } catch (NativeDaemonConnectorException e) {
        /*
         * Mount failed for some reason
         */
        String action = null;
        int code = e.getCode();
        if (code == VoldResponseCode.OpFailedNoMedia) {
            /*
             * Attempt to mount but no media inserted
             */
            rc = StorageResultCode.OperationFailedNoMedia;
        } else if (code == VoldResponseCode.OpFailedMediaBlank) {
            if (DEBUG_EVENTS)
                Slog.i(TAG, " updating volume state :: media nofs");
            /*
             * Media is blank or does not contain a supported filesystem
             */
            updatePublicVolumeState(volume, Environment.MEDIA_NOFS);
            action = Intent.ACTION_MEDIA_NOFS;
            rc = StorageResultCode.OperationFailedMediaBlank;
        } else if (code == VoldResponseCode.OpFailedMediaCorrupt) {
            if (DEBUG_EVENTS)
                Slog.i(TAG, "updating volume state media corrupt");
            /*
             * Volume consistency check failed
             */
            updatePublicVolumeState(volume, Environment.MEDIA_UNMOUNTABLE);
            action = Intent.ACTION_MEDIA_UNMOUNTABLE;
            rc = StorageResultCode.OperationFailedMediaCorrupt;
        } else {
            rc = StorageResultCode.OperationFailedInternalError;
        }

        /*
         * Send broadcast intent (if required for the failure)
         */
        if (action != null) {
            sendStorageIntent(action, volume, UserHandle.ALL);
        }
    }

    return rc;
}

From source file:com.android.server.MountService.java

public void shutdown(final IMountShutdownObserver observer) {
    validatePermission(android.Manifest.permission.SHUTDOWN);

    Slog.i(TAG, "Shutting down");
    synchronized (mVolumesLock) {
        // Get all volumes to be unmounted.
        MountShutdownLatch mountShutdownLatch = new MountShutdownLatch(observer, mVolumeStates.size());

        for (String path : mVolumeStates.keySet()) {
            String state = mVolumeStates.get(path);

            if (state.equals(Environment.MEDIA_SHARED)) {
                /*//from w ww.j a  va2s  . c  om
                 * If the media is currently shared, unshare it.
                 * XXX: This is still dangerous!. We should not
                 * be rebooting at *all* if UMS is enabled, since
                 * the UMS host could have dirty FAT cache entries
                 * yet to flush.
                 */
                setUsbMassStorageEnabled(false);
            } else if (state.equals(Environment.MEDIA_CHECKING)) {
                /*
                 * If the media is being checked, then we need to wait for
                 * it to complete before being able to proceed.
                 */
                // XXX: @hackbod - Should we disable the ANR timer here?
                int retries = 30;
                while (state.equals(Environment.MEDIA_CHECKING) && (retries-- >= 0)) {
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException iex) {
                        Slog.e(TAG, "Interrupted while waiting for media", iex);
                        break;
                    }
                    state = Environment.getExternalStorageState();
                }
                if (retries == 0) {
                    Slog.e(TAG, "Timed out waiting for media to check");
                }
            }

            if (state.equals(Environment.MEDIA_MOUNTED)) {
                // Post a unmount message.
                ShutdownCallBack ucb = new ShutdownCallBack(path, mountShutdownLatch);
                mHandler.sendMessage(mHandler.obtainMessage(H_UNMOUNT_PM_UPDATE, ucb));
            } else if (observer != null) {
                /*
                 * Count down, since nothing will be done. The observer will be
                 * notified when we are done so shutdown sequence can continue.
                 */
                mountShutdownLatch.countDown();
                Slog.i(TAG, "Unmount completed: " + path + ", result code: "
                        + StorageResultCode.OperationSucceeded);
            }
        }
    }
}

From source file:com.android.server.MountService.java

public void unmountVolume(String path, boolean force, boolean removeEncryption) {
    validatePermission(android.Manifest.permission.MOUNT_UNMOUNT_FILESYSTEMS);
    waitForReady();//from ww w.  jav  a  2s .  com

    String volState = getVolumeState(path);
    if (DEBUG_UNMOUNT) {
        Slog.i(TAG, "Unmounting " + path + " force = " + force + " removeEncryption = " + removeEncryption);
    }
    if (Environment.MEDIA_UNMOUNTED.equals(volState) || Environment.MEDIA_REMOVED.equals(volState)
            || Environment.MEDIA_SHARED.equals(volState) || Environment.MEDIA_UNMOUNTABLE.equals(volState)) {
        // Media already unmounted or cannot be unmounted.
        // TODO return valid return code when adding observer call back.
        return;
    }
    UnmountCallBack ucb = new UnmountCallBack(path, force, removeEncryption);
    mHandler.sendMessage(mHandler.obtainMessage(H_UNMOUNT_PM_UPDATE, ucb));
}

From source file:android.content.pm.PackageParser.java

/**
 * Parse the manifest of a <em>base APK</em>.
 * <p>//w ww . j  a v a2  s  . c  om
 * When adding new features, carefully consider if they should also be
 * supported by split APKs.
 */
private Package parseBaseApk(Resources res, XmlResourceParser parser, int flags, String[] outError)
        throws XmlPullParserException, IOException {
    final boolean trustedOverlay = (flags & PARSE_TRUSTED_OVERLAY) != 0;

    AttributeSet attrs = parser;

    mParseInstrumentationArgs = null;
    mParseActivityArgs = null;
    mParseServiceArgs = null;
    mParseProviderArgs = null;

    final String pkgName;
    final String splitName;
    try {
        Pair<String, String> packageSplit = parsePackageSplitNames(parser, attrs, flags);
        pkgName = packageSplit.first;
        splitName = packageSplit.second;
    } catch (PackageParserException e) {
        mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME;
        return null;
    }

    int type;

    if (!TextUtils.isEmpty(splitName)) {
        outError[0] = "Expected base APK, but found split " + splitName;
        mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME;
        return null;
    }

    final Package pkg = new Package(pkgName);
    boolean foundApp = false;

    TypedArray sa = res.obtainAttributes(attrs, com.android.internal.R.styleable.AndroidManifest);
    pkg.mVersionCode = pkg.applicationInfo.versionCode = sa
            .getInteger(com.android.internal.R.styleable.AndroidManifest_versionCode, 0);
    pkg.baseRevisionCode = sa.getInteger(com.android.internal.R.styleable.AndroidManifest_revisionCode, 0);
    pkg.mVersionName = sa
            .getNonConfigurationString(com.android.internal.R.styleable.AndroidManifest_versionName, 0);
    if (pkg.mVersionName != null) {
        pkg.mVersionName = pkg.mVersionName.intern();
    }
    String str = sa.getNonConfigurationString(com.android.internal.R.styleable.AndroidManifest_sharedUserId, 0);
    if (str != null && str.length() > 0) {
        String nameError = validateName(str, true, false);
        if (nameError != null && !"android".equals(pkgName)) {
            outError[0] = "<manifest> specifies bad sharedUserId name \"" + str + "\": " + nameError;
            mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_SHARED_USER_ID;
            return null;
        }
        pkg.mSharedUserId = str.intern();
        pkg.mSharedUserLabel = sa
                .getResourceId(com.android.internal.R.styleable.AndroidManifest_sharedUserLabel, 0);
    }

    pkg.installLocation = sa.getInteger(com.android.internal.R.styleable.AndroidManifest_installLocation,
            PARSE_DEFAULT_INSTALL_LOCATION);
    pkg.applicationInfo.installLocation = pkg.installLocation;

    pkg.coreApp = attrs.getAttributeBooleanValue(null, "coreApp", false);

    sa.recycle();

    /* Set the global "forward lock" flag */
    if ((flags & PARSE_FORWARD_LOCK) != 0) {
        pkg.applicationInfo.privateFlags |= ApplicationInfo.PRIVATE_FLAG_FORWARD_LOCK;
    }

    /* Set the global "on SD card" flag */
    if ((flags & PARSE_EXTERNAL_STORAGE) != 0) {
        pkg.applicationInfo.flags |= ApplicationInfo.FLAG_EXTERNAL_STORAGE;
    }

    // Resource boolean are -1, so 1 means we don't know the value.
    int supportsSmallScreens = 1;
    int supportsNormalScreens = 1;
    int supportsLargeScreens = 1;
    int supportsXLargeScreens = 1;
    int resizeable = 1;
    int anyDensity = 1;

    int outerDepth = parser.getDepth();
    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("application")) {
            if (foundApp) {
                if (RIGID_PARSER) {
                    outError[0] = "<manifest> has more than one <application>";
                    mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
                    return null;
                } else {
                    Slog.w(TAG, "<manifest> has more than one <application>");
                    XmlUtils.skipCurrentTag(parser);
                    continue;
                }
            }

            foundApp = true;
            if (!parseBaseApplication(pkg, res, parser, attrs, flags, outError)) {
                return null;
            }
        } else if (tagName.equals("overlay")) {
            pkg.mTrustedOverlay = trustedOverlay;

            sa = res.obtainAttributes(attrs, com.android.internal.R.styleable.AndroidManifestResourceOverlay);
            pkg.mOverlayTarget = sa
                    .getString(com.android.internal.R.styleable.AndroidManifestResourceOverlay_targetPackage);
            pkg.mOverlayPriority = sa
                    .getInt(com.android.internal.R.styleable.AndroidManifestResourceOverlay_priority, -1);
            sa.recycle();

            if (pkg.mOverlayTarget == null) {
                outError[0] = "<overlay> does not specify a target package";
                mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
                return null;
            }
            if (pkg.mOverlayPriority < 0 || pkg.mOverlayPriority > 9999) {
                outError[0] = "<overlay> priority must be between 0 and 9999";
                mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
                return null;
            }
            XmlUtils.skipCurrentTag(parser);

        } else if (tagName.equals("key-sets")) {
            if (!parseKeySets(pkg, res, parser, attrs, outError)) {
                return null;
            }
        } else if (tagName.equals("permission-group")) {
            if (parsePermissionGroup(pkg, flags, res, parser, attrs, outError) == null) {
                return null;
            }
        } else if (tagName.equals("permission")) {
            if (parsePermission(pkg, res, parser, attrs, outError) == null) {
                return null;
            }
        } else if (tagName.equals("permission-tree")) {
            if (parsePermissionTree(pkg, res, parser, attrs, outError) == null) {
                return null;
            }
        } else if (tagName.equals("uses-permission")) {
            if (!parseUsesPermission(pkg, res, parser, attrs)) {
                return null;
            }
        } else if (tagName.equals("uses-permission-sdk-m") || tagName.equals("uses-permission-sdk-23")) {
            if (!parseUsesPermission(pkg, res, parser, attrs)) {
                return null;
            }
        } else if (tagName.equals("uses-configuration")) {
            ConfigurationInfo cPref = new ConfigurationInfo();
            sa = res.obtainAttributes(attrs, com.android.internal.R.styleable.AndroidManifestUsesConfiguration);
            cPref.reqTouchScreen = sa.getInt(
                    com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqTouchScreen,
                    Configuration.TOUCHSCREEN_UNDEFINED);
            cPref.reqKeyboardType = sa.getInt(
                    com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqKeyboardType,
                    Configuration.KEYBOARD_UNDEFINED);
            if (sa.getBoolean(com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqHardKeyboard,
                    false)) {
                cPref.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_HARD_KEYBOARD;
            }
            cPref.reqNavigation = sa.getInt(
                    com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqNavigation,
                    Configuration.NAVIGATION_UNDEFINED);
            if (sa.getBoolean(com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqFiveWayNav,
                    false)) {
                cPref.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_FIVE_WAY_NAV;
            }
            sa.recycle();
            pkg.configPreferences = ArrayUtils.add(pkg.configPreferences, cPref);

            XmlUtils.skipCurrentTag(parser);

        } else if (tagName.equals("uses-feature")) {
            FeatureInfo fi = parseUsesFeature(res, attrs);
            pkg.reqFeatures = ArrayUtils.add(pkg.reqFeatures, fi);

            if (fi.name == null) {
                ConfigurationInfo cPref = new ConfigurationInfo();
                cPref.reqGlEsVersion = fi.reqGlEsVersion;
                pkg.configPreferences = ArrayUtils.add(pkg.configPreferences, cPref);
            }

            XmlUtils.skipCurrentTag(parser);

        } else if (tagName.equals("feature-group")) {
            FeatureGroupInfo group = new FeatureGroupInfo();
            ArrayList<FeatureInfo> features = null;
            final int innerDepth = parser.getDepth();
            while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
                    && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth)) {
                if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
                    continue;
                }

                final String innerTagName = parser.getName();
                if (innerTagName.equals("uses-feature")) {
                    FeatureInfo featureInfo = parseUsesFeature(res, attrs);
                    // FeatureGroups are stricter and mandate that
                    // any <uses-feature> declared are mandatory.
                    featureInfo.flags |= FeatureInfo.FLAG_REQUIRED;
                    features = ArrayUtils.add(features, featureInfo);
                } else {
                    Slog.w(TAG, "Unknown element under <feature-group>: " + innerTagName + " at "
                            + mArchiveSourcePath + " " + parser.getPositionDescription());
                }
                XmlUtils.skipCurrentTag(parser);
            }

            if (features != null) {
                group.features = new FeatureInfo[features.size()];
                group.features = features.toArray(group.features);
            }
            pkg.featureGroups = ArrayUtils.add(pkg.featureGroups, group);

        } else if (tagName.equals("uses-sdk")) {
            if (SDK_VERSION > 0) {
                sa = res.obtainAttributes(attrs, com.android.internal.R.styleable.AndroidManifestUsesSdk);

                int minVers = 0;
                String minCode = null;
                int targetVers = 0;
                String targetCode = null;

                TypedValue val = sa
                        .peekValue(com.android.internal.R.styleable.AndroidManifestUsesSdk_minSdkVersion);
                if (val != null) {
                    if (val.type == TypedValue.TYPE_STRING && val.string != null) {
                        targetCode = minCode = val.string.toString();
                    } else {
                        // If it's not a string, it's an integer.
                        targetVers = minVers = val.data;
                    }
                }

                val = sa.peekValue(com.android.internal.R.styleable.AndroidManifestUsesSdk_targetSdkVersion);
                if (val != null) {
                    if (val.type == TypedValue.TYPE_STRING && val.string != null) {
                        targetCode = minCode = val.string.toString();
                    } else {
                        // If it's not a string, it's an integer.
                        targetVers = val.data;
                    }
                }

                sa.recycle();

                if (minCode != null) {
                    boolean allowedCodename = false;
                    for (String codename : SDK_CODENAMES) {
                        if (minCode.equals(codename)) {
                            allowedCodename = true;
                            break;
                        }
                    }
                    if (!allowedCodename) {
                        if (SDK_CODENAMES.length > 0) {
                            outError[0] = "Requires development platform " + minCode
                                    + " (current platform is any of " + Arrays.toString(SDK_CODENAMES) + ")";
                        } else {
                            outError[0] = "Requires development platform " + minCode
                                    + " but this is a release platform.";
                        }
                        mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
                        return null;
                    }
                } else if (minVers > SDK_VERSION) {
                    outError[0] = "Requires newer sdk version #" + minVers + " (current version is #"
                            + SDK_VERSION + ")";
                    mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
                    return null;
                }

                if (targetCode != null) {
                    boolean allowedCodename = false;
                    for (String codename : SDK_CODENAMES) {
                        if (targetCode.equals(codename)) {
                            allowedCodename = true;
                            break;
                        }
                    }
                    if (!allowedCodename) {
                        if (SDK_CODENAMES.length > 0) {
                            outError[0] = "Requires development platform " + targetCode
                                    + " (current platform is any of " + Arrays.toString(SDK_CODENAMES) + ")";
                        } else {
                            outError[0] = "Requires development platform " + targetCode
                                    + " but this is a release platform.";
                        }
                        mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
                        return null;
                    }
                    // If the code matches, it definitely targets this SDK.
                    pkg.applicationInfo.targetSdkVersion = android.os.Build.VERSION_CODES.CUR_DEVELOPMENT;
                } else {
                    pkg.applicationInfo.targetSdkVersion = targetVers;
                }
            }

            XmlUtils.skipCurrentTag(parser);

        } else if (tagName.equals("supports-screens")) {
            sa = res.obtainAttributes(attrs, com.android.internal.R.styleable.AndroidManifestSupportsScreens);

            pkg.applicationInfo.requiresSmallestWidthDp = sa.getInteger(
                    com.android.internal.R.styleable.AndroidManifestSupportsScreens_requiresSmallestWidthDp, 0);
            pkg.applicationInfo.compatibleWidthLimitDp = sa.getInteger(
                    com.android.internal.R.styleable.AndroidManifestSupportsScreens_compatibleWidthLimitDp, 0);
            pkg.applicationInfo.largestWidthLimitDp = sa.getInteger(
                    com.android.internal.R.styleable.AndroidManifestSupportsScreens_largestWidthLimitDp, 0);

            // This is a trick to get a boolean and still able to detect
            // if a value was actually set.
            supportsSmallScreens = sa.getInteger(
                    com.android.internal.R.styleable.AndroidManifestSupportsScreens_smallScreens,
                    supportsSmallScreens);
            supportsNormalScreens = sa.getInteger(
                    com.android.internal.R.styleable.AndroidManifestSupportsScreens_normalScreens,
                    supportsNormalScreens);
            supportsLargeScreens = sa.getInteger(
                    com.android.internal.R.styleable.AndroidManifestSupportsScreens_largeScreens,
                    supportsLargeScreens);
            supportsXLargeScreens = sa.getInteger(
                    com.android.internal.R.styleable.AndroidManifestSupportsScreens_xlargeScreens,
                    supportsXLargeScreens);
            resizeable = sa.getInteger(
                    com.android.internal.R.styleable.AndroidManifestSupportsScreens_resizeable, resizeable);
            anyDensity = sa.getInteger(
                    com.android.internal.R.styleable.AndroidManifestSupportsScreens_anyDensity, anyDensity);

            sa.recycle();

            XmlUtils.skipCurrentTag(parser);

        } else if (tagName.equals("protected-broadcast")) {
            sa = res.obtainAttributes(attrs,
                    com.android.internal.R.styleable.AndroidManifestProtectedBroadcast);

            // Note: don't allow this value to be a reference to a resource
            // that may change.
            String name = sa.getNonResourceString(
                    com.android.internal.R.styleable.AndroidManifestProtectedBroadcast_name);

            sa.recycle();

            if (name != null && (flags & PARSE_IS_SYSTEM) != 0) {
                if (pkg.protectedBroadcasts == null) {
                    pkg.protectedBroadcasts = new ArrayList<String>();
                }
                if (!pkg.protectedBroadcasts.contains(name)) {
                    pkg.protectedBroadcasts.add(name.intern());
                }
            }

            XmlUtils.skipCurrentTag(parser);

        } else if (tagName.equals("instrumentation")) {
            if (parseInstrumentation(pkg, res, parser, attrs, outError) == null) {
                return null;
            }

        } else if (tagName.equals("original-package")) {
            sa = res.obtainAttributes(attrs, com.android.internal.R.styleable.AndroidManifestOriginalPackage);

            String orig = sa.getNonConfigurationString(
                    com.android.internal.R.styleable.AndroidManifestOriginalPackage_name, 0);
            if (!pkg.packageName.equals(orig)) {
                if (pkg.mOriginalPackages == null) {
                    pkg.mOriginalPackages = new ArrayList<String>();
                    pkg.mRealPackage = pkg.packageName;
                }
                pkg.mOriginalPackages.add(orig);
            }

            sa.recycle();

            XmlUtils.skipCurrentTag(parser);

        } else if (tagName.equals("adopt-permissions")) {
            sa = res.obtainAttributes(attrs, com.android.internal.R.styleable.AndroidManifestOriginalPackage);

            String name = sa.getNonConfigurationString(
                    com.android.internal.R.styleable.AndroidManifestOriginalPackage_name, 0);

            sa.recycle();

            if (name != null) {
                if (pkg.mAdoptPermissions == null) {
                    pkg.mAdoptPermissions = new ArrayList<String>();
                }
                pkg.mAdoptPermissions.add(name);
            }

            XmlUtils.skipCurrentTag(parser);

        } else if (tagName.equals("uses-gl-texture")) {
            // Just skip this tag
            XmlUtils.skipCurrentTag(parser);
            continue;

        } else if (tagName.equals("compatible-screens")) {
            // Just skip this tag
            XmlUtils.skipCurrentTag(parser);
            continue;
        } else if (tagName.equals("supports-input")) {
            XmlUtils.skipCurrentTag(parser);
            continue;

        } else if (tagName.equals("eat-comment")) {
            // Just skip this tag
            XmlUtils.skipCurrentTag(parser);
            continue;

        } else if (RIGID_PARSER) {
            outError[0] = "Bad element under <manifest>: " + parser.getName();
            mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
            return null;

        } else {
            Slog.w(TAG, "Unknown element under <manifest>: " + parser.getName() + " at " + mArchiveSourcePath
                    + " " + parser.getPositionDescription());
            XmlUtils.skipCurrentTag(parser);
            continue;
        }
    }

    if (!foundApp && pkg.instrumentation.size() == 0) {
        outError[0] = "<manifest> does not contain an <application> or <instrumentation>";
        mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_EMPTY;
    }

    final int NP = PackageParser.NEW_PERMISSIONS.length;
    StringBuilder implicitPerms = null;
    for (int ip = 0; ip < NP; ip++) {
        final PackageParser.NewPermissionInfo npi = PackageParser.NEW_PERMISSIONS[ip];
        if (pkg.applicationInfo.targetSdkVersion >= npi.sdkVersion) {
            break;
        }
        if (!pkg.requestedPermissions.contains(npi.name)) {
            if (implicitPerms == null) {
                implicitPerms = new StringBuilder(128);
                implicitPerms.append(pkg.packageName);
                implicitPerms.append(": compat added ");
            } else {
                implicitPerms.append(' ');
            }
            implicitPerms.append(npi.name);
            pkg.requestedPermissions.add(npi.name);
        }
    }
    if (implicitPerms != null) {
        Slog.i(TAG, implicitPerms.toString());
    }

    final int NS = PackageParser.SPLIT_PERMISSIONS.length;
    for (int is = 0; is < NS; is++) {
        final PackageParser.SplitPermissionInfo spi = PackageParser.SPLIT_PERMISSIONS[is];
        if (pkg.applicationInfo.targetSdkVersion >= spi.targetSdk
                || !pkg.requestedPermissions.contains(spi.rootPerm)) {
            continue;
        }
        for (int in = 0; in < spi.newPerms.length; in++) {
            final String perm = spi.newPerms[in];
            if (!pkg.requestedPermissions.contains(perm)) {
                pkg.requestedPermissions.add(perm);
            }
        }
    }

    if (supportsSmallScreens < 0 || (supportsSmallScreens > 0
            && pkg.applicationInfo.targetSdkVersion >= android.os.Build.VERSION_CODES.DONUT)) {
        pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SMALL_SCREENS;
    }
    if (supportsNormalScreens != 0) {
        pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_NORMAL_SCREENS;
    }
    if (supportsLargeScreens < 0 || (supportsLargeScreens > 0
            && pkg.applicationInfo.targetSdkVersion >= android.os.Build.VERSION_CODES.DONUT)) {
        pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS;
    }
    if (supportsXLargeScreens < 0 || (supportsXLargeScreens > 0
            && pkg.applicationInfo.targetSdkVersion >= android.os.Build.VERSION_CODES.GINGERBREAD)) {
        pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_XLARGE_SCREENS;
    }
    if (resizeable < 0 || (resizeable > 0
            && pkg.applicationInfo.targetSdkVersion >= android.os.Build.VERSION_CODES.DONUT)) {
        pkg.applicationInfo.flags |= ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS;
    }
    if (anyDensity < 0 || (anyDensity > 0
            && pkg.applicationInfo.targetSdkVersion >= android.os.Build.VERSION_CODES.DONUT)) {
        pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES;
    }

    return pkg;
}

From source file:com.android.server.MountService.java

public String getSecureContainerPath(String id) {
    validatePermission(android.Manifest.permission.ASEC_ACCESS);
    waitForReady();//from  ww  w  .j av a2s.c  o m
    warnOnNotMounted();

    final NativeDaemonEvent event;
    try {
        event = mConnector.execute("asec", "path", id);
        event.checkCode(VoldResponseCode.AsecPathResult);
        return event.getMessage();
    } catch (NativeDaemonConnectorException e) {
        int code = e.getCode();
        if (code == VoldResponseCode.OpFailedStorageNotFound) {
            Slog.i(TAG, String.format("Container '%s' not found", id));
            return null;
        } else {
            throw new IllegalStateException(String.format("Unexpected response code %d", code));
        }
    }
}

From source file:com.android.server.MountService.java

public String getSecureContainerFilesystemPath(String id) {
    validatePermission(android.Manifest.permission.ASEC_ACCESS);
    waitForReady();/*from w  w  w  . j a va 2 s  . co m*/
    warnOnNotMounted();

    final NativeDaemonEvent event;
    try {
        event = mConnector.execute("asec", "fspath", id);
        event.checkCode(VoldResponseCode.AsecPathResult);
        return event.getMessage();
    } catch (NativeDaemonConnectorException e) {
        int code = e.getCode();
        if (code == VoldResponseCode.OpFailedStorageNotFound) {
            Slog.i(TAG, String.format("Container '%s' not found", id));
            return null;
        } else {
            throw new IllegalStateException(String.format("Unexpected response code %d", code));
        }
    }
}

From source file:com.android.server.MountService.java

@Override
public void mountObb(String rawPath, String canonicalPath, String key, IObbActionListener token, int nonce) {
    Preconditions.checkNotNull(rawPath, "rawPath cannot be null");
    Preconditions.checkNotNull(canonicalPath, "canonicalPath cannot be null");
    Preconditions.checkNotNull(token, "token cannot be null");

    final int callingUid = Binder.getCallingUid();
    final ObbState obbState = new ObbState(rawPath, canonicalPath, callingUid, token, nonce);
    final ObbAction action = new MountObbAction(obbState, key, callingUid);
    mObbActionHandler.sendMessage(mObbActionHandler.obtainMessage(OBB_RUN_ACTION, action));

    if (DEBUG_OBB)
        Slog.i(TAG, "Send to OBB handler: " + action.toString());
}