Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 66835b85 authored by Xiaogang Cui's avatar Xiaogang Cui Committed by Gerrit - the friendly Code Review server
Browse files

frameworks: base: add check to avoid runtime exception

When user switch to guest mode, the secondary storage is not
added. Add check for array to avoid runtime exceptions.

Change-Id: I3bb27c9963007b01fe8ca67dc7ef9e3574c26fc9
parent 1141e950
Loading
Loading
Loading
Loading
+10 −4
Original line number Diff line number Diff line
@@ -177,7 +177,12 @@ public class Environment {

        /** {@hide} */
        public File getSecondaryStorageDirectory() {
            /* If switch to guest account
             * The secondary storage will not be added into externalForApp
             */
            if (mExternalDirsForApp.length > 1)
                return mExternalDirsForApp[1];
            return null;
        }

        @Deprecated
@@ -429,7 +434,9 @@ public class Environment {
    /** {@hide} */
    public static File getSecondaryStorageDirectory() {
        throwIfUserRequired();
        if (sCurrentUser.getExternalDirsForApp().length > 1)
            return sCurrentUser.getExternalDirsForApp()[1];
        return null;
    }

    /** {@hide} */
@@ -756,8 +763,7 @@ public class Environment {
     * @hide
     */
    public static String getSecondaryStorageState() {
        final File externalDir = sCurrentUser.getExternalDirsForApp()[1];
        return getStorageState(externalDir);
        return getStorageState(getSecondaryStorageDirectory());
    }

    /**