Example usage for android.util Slog e

List of usage examples for android.util Slog e

Introduction

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

Prototype

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

Source Link

Usage

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

private void handleSystemReady() {
    // Snapshot current volume states since it's not safe to call into vold
    // while holding locks.
    final HashMap<String, String> snapshot;
    synchronized (mVolumesLock) {
        snapshot = new HashMap<String, String>(mVolumeStates);
    }//w w  w .  j a  v  a  2s  .  co  m

    for (Map.Entry<String, String> entry : snapshot.entrySet()) {
        final String path = entry.getKey();
        final String state = entry.getValue();

        if (state.equals(Environment.MEDIA_UNMOUNTED)) {
            int rc = doMountVolume(path);
            if (rc != StorageResultCode.OperationSucceeded) {
                Slog.e(TAG, String.format("Boot-time mount failed (%d)", rc));
            }
        } else if (state.equals(Environment.MEDIA_SHARED)) {
            /*
             * Bootstrap UMS enabled state since vold indicates
             * the volume is shared (runtime restart while ums enabled)
             */
            notifyVolumeStateChange(null, path, VolumeState.NoMedia, VolumeState.Shared);
        }
    }

    // Push mounted state for all emulated storage
    synchronized (mVolumesLock) {
        for (StorageVolume volume : mVolumes) {
            if (volume.isEmulated()) {
                updatePublicVolumeState(volume, Environment.MEDIA_MOUNTED);
            }
        }
    }

    /*
     * If UMS was connected on boot, send the connected event
     * now that we're up.
     */
    if (mSendUmsConnectedOnBoot) {
        sendUmsIntent(true);
        mSendUmsConnectedOnBoot = false;
    }

    /*
     * Start scheduling nominally-daily fstrim operations
     */
    MountServiceIdler.scheduleIdlePass(mContext);
}

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

private void updatePublicVolumeState(StorageVolume volume, String state) {
    final String path = volume.getPath();
    final String oldState;
    synchronized (mVolumesLock) {
        oldState = mVolumeStates.put(path, state);
        volume.setState(state);/* w w w. j  a  va  2  s  .c o  m*/
    }

    if (state.equals(oldState)) {
        Slog.w(TAG, String.format("Duplicate state transition (%s -> %s) for %s", state, state, path));
        return;
    }

    Slog.d(TAG, "volume state changed for " + path + " (" + oldState + " -> " + state + ")");

    // Tell PackageManager about changes to primary volume state, but only
    // when not emulated.
    if (volume.isPrimary() && !volume.isEmulated()) {
        if (Environment.MEDIA_UNMOUNTED.equals(state)) {
            mPms.updateExternalMediaStatus(false, false);

            /*
             * Some OBBs might have been unmounted when this volume was
             * unmounted, so send a message to the handler to let it know to
             * remove those from the list of mounted OBBS.
             */
            mObbActionHandler.sendMessage(mObbActionHandler.obtainMessage(OBB_FLUSH_MOUNT_STATE, path));
        } else if (Environment.MEDIA_MOUNTED.equals(state)) {
            mPms.updateExternalMediaStatus(true, false);
        }
    }

    synchronized (mListeners) {
        for (int i = mListeners.size() - 1; i >= 0; i--) {
            MountServiceBinderListener bl = mListeners.get(i);
            try {
                bl.mListener.onStorageStateChanged(path, oldState, state);
            } catch (RemoteException rex) {
                Slog.e(TAG, "Listener dead");
                mListeners.remove(i);
            } catch (Exception ex) {
                Slog.e(TAG, "Listener failed", ex);
            }
        }
    }
}

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  va  2 s  .  c om
    }

    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 boolean doGetVolumeShared(String path, String method) {
    final NativeDaemonEvent event;
    try {// www .java2 s  .co  m
        event = mConnector.execute("volume", "shared", path, method);
    } catch (NativeDaemonConnectorException ex) {
        Slog.e(TAG, "Failed to read response to volume shared " + path + " " + method);
        return false;
    }

    if (event.getCode() == VoldResponseCode.ShareEnabledResult) {
        return event.getMessage().endsWith("enabled");
    } else {
        return false;
    }
}

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

private void notifyShareAvailabilityChange(final boolean avail) {
    synchronized (mListeners) {
        mUmsAvailable = avail;/*from w  w  w.jav  a 2 s  .c  o m*/
        for (int i = mListeners.size() - 1; i >= 0; i--) {
            MountServiceBinderListener bl = mListeners.get(i);
            try {
                bl.mListener.onUsbMassStorageConnectionChanged(avail);
            } catch (RemoteException rex) {
                Slog.e(TAG, "Listener dead");
                mListeners.remove(i);
            } catch (Exception ex) {
                Slog.e(TAG, "Listener failed", ex);
            }
        }
    }

    if (mSystemReady == true) {
        sendUmsIntent(avail);
    } else {
        mSendUmsConnectedOnBoot = avail;
    }

    final StorageVolume primary = getPrimaryPhysicalVolume();
    if (avail == false && primary != null
            && Environment.MEDIA_SHARED.equals(getVolumeState(primary.getPath()))) {
        final String path = primary.getPath();
        /*
         * USB mass storage disconnected while enabled
         */
        new Thread("MountService#AvailabilityChange") {
            @Override
            public void run() {
                try {
                    int rc;
                    Slog.w(TAG, "Disabling UMS after cable disconnect");
                    doShareUnshareVolume(path, "ums", false);
                    if ((rc = doMountVolume(path)) != StorageResultCode.OperationSucceeded) {
                        Slog.e(TAG, String.format("Failed to remount {%s} on UMS enabled-disconnect (%d)", path,
                                rc));
                    }
                } catch (Exception ex) {
                    Slog.w(TAG, "Failed to mount media on UMS enabled-disconnect", ex);
                }
            }
        }.start();
    }
}

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

private void readStorageListLocked() {
    mVolumes.clear();// w  w  w.j a va  2  s .  co  m
    mVolumeStates.clear();

    Resources resources = mContext.getResources();

    int id = com.android.internal.R.xml.storage_list;
    XmlResourceParser parser = resources.getXml(id);
    AttributeSet attrs = Xml.asAttributeSet(parser);

    try {
        XmlUtils.beginDocument(parser, TAG_STORAGE_LIST);
        while (true) {
            XmlUtils.nextElement(parser);

            String element = parser.getName();
            if (element == null)
                break;

            if (TAG_STORAGE.equals(element)) {
                TypedArray a = resources.obtainAttributes(attrs, com.android.internal.R.styleable.Storage);

                String path = a.getString(com.android.internal.R.styleable.Storage_mountPoint);
                int descriptionId = a.getResourceId(com.android.internal.R.styleable.Storage_storageDescription,
                        -1);
                CharSequence description = a
                        .getText(com.android.internal.R.styleable.Storage_storageDescription);
                boolean primary = a.getBoolean(com.android.internal.R.styleable.Storage_primary, false);
                boolean removable = a.getBoolean(com.android.internal.R.styleable.Storage_removable, false);
                boolean emulated = a.getBoolean(com.android.internal.R.styleable.Storage_emulated, false);
                int mtpReserve = a.getInt(com.android.internal.R.styleable.Storage_mtpReserve, 0);
                boolean allowMassStorage = a
                        .getBoolean(com.android.internal.R.styleable.Storage_allowMassStorage, false);
                boolean allowMtp = a.getBoolean(com.android.internal.R.styleable.Storage_allowMtp, true);
                // resource parser does not support longs, so XML value is in megabytes
                long maxFileSize = a.getInt(com.android.internal.R.styleable.Storage_maxFileSize, 0) * 1024L
                        * 1024L;

                Slog.d(TAG,
                        "got storage path: " + path + " description: " + description + " primary: " + primary
                                + " removable: " + removable + " emulated: " + emulated + " mtpReserve: "
                                + mtpReserve + " allowMassStorage: " + allowMassStorage + " maxFileSize: "
                                + maxFileSize + " allowMtp: " + allowMtp);

                if (emulated) {
                    // For devices with emulated storage, we create separate
                    // volumes for each known user.
                    mEmulatedTemplate = new StorageVolume(null, descriptionId, true, false, true, mtpReserve,
                            false, maxFileSize, null, allowMtp);

                    final UserManagerService userManager = UserManagerService.getInstance();
                    for (UserInfo user : userManager.getUsers(false)) {
                        createEmulatedVolumeForUserLocked(user.getUserHandle());
                    }

                } else {
                    if (path == null || description == null) {
                        Slog.e(TAG, "Missing storage path or description in readStorageList");
                    } else {
                        final StorageVolume volume = new StorageVolume(new File(path), descriptionId, primary,
                                removable, emulated, mtpReserve, allowMassStorage, maxFileSize, null, allowMtp);
                        addVolumeLocked(volume);

                        // Until we hear otherwise, treat as unmounted
                        mVolumeStates.put(volume.getPath(), Environment.MEDIA_UNMOUNTED);
                        volume.setState(Environment.MEDIA_UNMOUNTED);
                    }
                }

                a.recycle();
            }
        }
    } catch (XmlPullParserException e) {
        throw new RuntimeException(e);
    } catch (IOException e) {
        throw new RuntimeException(e);
    } finally {
        // Compute storage ID for each physical volume; emulated storage is
        // always 0 when defined.
        int index = isExternalStorageEmulated() ? 1 : 0;
        for (StorageVolume volume : mVolumes) {
            if (!volume.isEmulated()) {
                volume.setStorageId(index++);
            }
        }
        parser.close();
    }
}

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

/**
 * Constructs a new MountService instance
 *
 * @param context  Binder context for this service
 *//*from   ww w  .  ja va 2  s  . com*/
public MountService(Context context) {
    sSelf = this;

    mContext = context;

    synchronized (mVolumesLock) {
        readStorageListLocked();
    }

    // XXX: This will go away soon in favor of IMountServiceObserver
    mPms = (PackageManagerService) ServiceManager.getService("package");

    HandlerThread hthread = new HandlerThread(TAG);
    hthread.start();
    mHandler = new MountServiceHandler(hthread.getLooper());

    // Watch for user changes
    final IntentFilter userFilter = new IntentFilter();
    userFilter.addAction(Intent.ACTION_USER_ADDED);
    userFilter.addAction(Intent.ACTION_USER_REMOVED);
    mContext.registerReceiver(mUserReceiver, userFilter, null, mHandler);

    // Watch for USB changes on primary volume
    final StorageVolume primary = getPrimaryPhysicalVolume();
    if (primary != null && primary.allowMassStorage()) {
        mContext.registerReceiver(mUsbReceiver, new IntentFilter(UsbManager.ACTION_USB_STATE), null, mHandler);
    }

    // Add OBB Action Handler to MountService thread.
    mObbActionHandler = new ObbActionHandler(IoThread.get().getLooper());

    // Initialize the last-fstrim tracking if necessary
    File dataDir = Environment.getDataDirectory();
    File systemDir = new File(dataDir, "system");
    mLastMaintenanceFile = new File(systemDir, LAST_FSTRIM_FILE);
    if (!mLastMaintenanceFile.exists()) {
        // Not setting mLastMaintenance here means that we will force an
        // fstrim during reboot following the OTA that installs this code.
        try {
            (new FileOutputStream(mLastMaintenanceFile)).close();
        } catch (IOException e) {
            Slog.e(TAG, "Unable to create fstrim record " + mLastMaintenanceFile.getPath());
        }
    } else {
        mLastMaintenance = mLastMaintenanceFile.lastModified();
    }

    /*
     * Create the connection to vold with a maximum queue of twice the
     * amount of containers we'd ever expect to have. This keeps an
     * "asec list" from blocking a thread repeatedly.
     */
    mConnector = new NativeDaemonConnector(this, "vold", MAX_CONTAINERS * 2, VOLD_TAG, 25, null);

    Thread thread = new Thread(mConnector, VOLD_TAG);
    thread.start();

    // Add ourself to the Watchdog monitors if enabled.
    if (WATCHDOG_ENABLE) {
        Watchdog.getInstance().addMonitor(this);
    }
}

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

/**
 * Exposed API calls below here//from  www  .ja va  2s  . co m
 */

public void registerListener(IMountServiceListener listener) {
    synchronized (mListeners) {
        MountServiceBinderListener bl = new MountServiceBinderListener(listener);
        try {
            listener.asBinder().linkToDeath(bl, 0);
            mListeners.add(bl);
        } catch (RemoteException rex) {
            Slog.e(TAG, "Failed to link to listener death");
        }
    }
}

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

public void setUsbMassStorageEnabled(boolean enable) {
    waitForReady();/* ww  w  . j a va  2 s  . c  o m*/
    validatePermission(android.Manifest.permission.MOUNT_UNMOUNT_FILESYSTEMS);
    validateUserRestriction(UserManager.DISALLOW_USB_FILE_TRANSFER);

    final StorageVolume primary = getPrimaryPhysicalVolume();
    if (primary == null)
        return;

    // TODO: Add support for multiple share methods

    /*
     * If the volume is mounted and we're enabling then unmount it
     */
    String path = primary.getPath();
    String vs = getVolumeState(path);
    String method = "ums";
    if (enable && vs.equals(Environment.MEDIA_MOUNTED)) {
        // Override for isUsbMassStorageEnabled()
        setUmsEnabling(enable);
        UmsEnableCallBack umscb = new UmsEnableCallBack(path, method, true);
        mHandler.sendMessage(mHandler.obtainMessage(H_UNMOUNT_PM_UPDATE, umscb));
        // Clear override
        setUmsEnabling(false);
    }
    /*
     * If we disabled UMS then mount the volume
     */
    if (!enable) {
        doShareUnshareVolume(path, method, enable);
        if (doMountVolume(path) != StorageResultCode.OperationSucceeded) {
            Slog.e(TAG, "Failed to remount " + path + " after disabling share method " + method);
            /*
             * Even though the mount failed, the unshare didn't so don't indicate an error.
             * The mountVolume() call will have set the storage state and sent the necessary
             * broadcasts.
             */
        }
    }
}

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

public int[] getStorageUsers(String path) {
    validatePermission(android.Manifest.permission.MOUNT_UNMOUNT_FILESYSTEMS);
    waitForReady();/*  w w w .j  ava  2s  .c o  m*/
    try {
        final String[] r = NativeDaemonEvent.filterMessageList(
                mConnector.executeForList("storage", "users", path), VoldResponseCode.StorageUsersListResult);

        // FMT: <pid> <process name>
        int[] data = new int[r.length];
        for (int i = 0; i < r.length; i++) {
            String[] tok = r[i].split(" ");
            try {
                data[i] = Integer.parseInt(tok[0]);
            } catch (NumberFormatException nfe) {
                Slog.e(TAG, String.format("Error parsing pid %s", tok[0]));
                return new int[0];
            }
        }
        return data;
    } catch (NativeDaemonConnectorException e) {
        Slog.e(TAG, "Failed to retrieve storage users list", e);
        return new int[0];
    }
}