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

Commit a2b6c377 authored by Suchi Amalapurapu's avatar Suchi Amalapurapu
Browse files

Add conditions to check for updated system applications. Restrict them

to internal flash only even before we copy.

Return error codes when install flag options mismatch.
Some conditions for existings apps
 - install flags override existing location
 - explicity manifest option install location overrides previous location
 - if upgraded package's install location is unspecified or auto, fall
   back to recommended install policy which considers user setting as well.

Check for sdcard status before finding available size on sdcard
Add light weight parsing for manifest attributes including package name and
install location only

Change-Id: I5143dda87c88c595f564b317326c926d0ec3ceb8
parent a9fb0a24
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -151,7 +151,7 @@ public class PackageInfo implements Parcelable {
     */
    public static final int INSTALL_LOCATION_PREFER_EXTERNAL = 2;
    /**
     * The launch mode style requested by the activity.  From the
     * The install location requested by the activity.  From the
     * {@link android.R.attr#installLocation} attribute, one of
     * {@link #INSTALL_LOCATION_AUTO},
     * {@link #INSTALL_LOCATION_INTERNAL_ONLY},
+20 −0
Original line number Diff line number Diff line
/* //device/java/android/android/view/WindowManager.aidl
**
** Copyright 2007, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License"); 
** you may not use this file except in compliance with the License. 
** You may obtain a copy of the License at 
**
**     http://www.apache.org/licenses/LICENSE-2.0 
**
** Unless required by applicable law or agreed to in writing, software 
** distributed under the License is distributed on an "AS IS" BASIS, 
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
** See the License for the specific language governing permissions and 
** limitations under the License.
*/

package android.content.pm;

parcelable PackageInfoLite;
+63 −0
Original line number Diff line number Diff line
package android.content.pm;

import android.os.Parcel;
import android.os.Parcelable;

/**
 * Basic information about a package as specified in its manifest.
 * Utility class used in PackageManager methods
 * @hide
 */
public class PackageInfoLite implements Parcelable {
    /**
     * The name of this package.  From the <manifest> tag's "name"
     * attribute.
     */
    public String packageName;

    /**
     * Specifies the recommended install location. Can be one of
     * {@link #PackageHelper.RECOMMEND_INSTALL_INTERNAL} to install on internal storage
     * {@link #PackageHelper.RECOMMEND_INSTALL_EXTERNAL} to install on external media
     * {@link PackageHelper.RECOMMEND_FAILED_INSUFFICIENT_STORAGE} for storage errors
     * {@link PackageHelper.RECOMMEND_FAILED_INVALID_APK} for parse errors.
     */
    public int recommendedInstallLocation;
    public int installLocation;

    public PackageInfoLite() {
    }

    public String toString() {
        return "PackageInfoLite{"
            + Integer.toHexString(System.identityHashCode(this))
            + " " + packageName + "}";
    }

    public int describeContents() {
        return 0;
    }

    public void writeToParcel(Parcel dest, int parcelableFlags) {
        dest.writeString(packageName);
        dest.writeInt(recommendedInstallLocation);
        dest.writeInt(installLocation);
    }

    public static final Parcelable.Creator<PackageInfoLite> CREATOR
            = new Parcelable.Creator<PackageInfoLite>() {
        public PackageInfoLite createFromParcel(Parcel source) {
            return new PackageInfoLite(source);
        }

        public PackageInfoLite[] newArray(int size) {
            return new PackageInfoLite[size];
        }
    };

    private PackageInfoLite(Parcel source) {
        packageName = source.readString();
        recommendedInstallLocation = source.readInt();
        installLocation = source.readInt();
    }
}
 No newline at end of file
+70 −7
Original line number Diff line number Diff line
@@ -137,6 +137,19 @@ public class PackageParser {
        }
    }

    /* Light weight package info.
     * @hide
     */
    public static class PackageLite {
        public String packageName;
        public int installLocation;
        public String mScanPath;
        public PackageLite(String packageName, int installLocation) {
            this.packageName = packageName;
            this.installLocation = installLocation;
        }
    }

    private ParsePackageItemArgs mParseInstrumentationArgs;
    private ParseComponentArgs mParseActivityArgs;
    private ParseComponentArgs mParseActivityAliasArgs;
@@ -562,7 +575,14 @@ public class PackageParser {
        return true;
    }

    public static String parsePackageName(String packageFilePath, int flags) {
    /*
     * Utility method that retrieves just the package name and install
     * location from the apk location at the given file path.
     * @param packageFilePath file location of the apk
     * @param flags Special parse flags
     * @return PackageLite object with package information.
     */
    public static PackageLite parsePackageLite(String packageFilePath, int flags) {
        XmlResourceParser parser = null;
        AssetManager assmgr = null;
        try {
@@ -577,9 +597,9 @@ public class PackageParser {
        }
        AttributeSet attrs = parser;
        String errors[] = new String[1];
        String packageName = null;
        PackageLite packageLite = null;
        try {
            packageName = parsePackageName(parser, attrs, flags, errors);
            packageLite = parsePackageLite(parser, attrs, flags, errors);
        } catch (IOException e) {
            Log.w(TAG, packageFilePath, e);
        } catch (XmlPullParserException e) {
@@ -588,11 +608,11 @@ public class PackageParser {
            if (parser != null) parser.close();
            if (assmgr != null) assmgr.close();
        }
        if (packageName == null) {
            Log.e(TAG, "parsePackageName error: " + errors[0]);
        if (packageLite == null) {
            Log.e(TAG, "parsePackageLite error: " + errors[0]);
            return null;
        }
        return packageName;
        return packageLite;
    }

    private static String validateName(String name, boolean requiresSeparator) {
@@ -656,6 +676,49 @@ public class PackageParser {
        return pkgName.intern();
    }

    private static PackageLite parsePackageLite(XmlPullParser parser,
            AttributeSet attrs, int flags, String[] outError)
            throws IOException, XmlPullParserException {

        int type;
        while ((type=parser.next()) != parser.START_TAG
                   && type != parser.END_DOCUMENT) {
            ;
        }

        if (type != parser.START_TAG) {
            outError[0] = "No start tag found";
            return null;
        }
        if ((flags&PARSE_CHATTY) != 0 && Config.LOGV) Log.v(
            TAG, "Root element name: '" + parser.getName() + "'");
        if (!parser.getName().equals("manifest")) {
            outError[0] = "No <manifest> tag";
            return null;
        }
        String pkgName = attrs.getAttributeValue(null, "package");
        if (pkgName == null || pkgName.length() == 0) {
            outError[0] = "<manifest> does not specify package";
            return null;
        }
        String nameError = validateName(pkgName, true);
        if (nameError != null && !"android".equals(pkgName)) {
            outError[0] = "<manifest> specifies bad package name \""
                + pkgName + "\": " + nameError;
            return null;
        }
        int installLocation = PackageInfo.INSTALL_LOCATION_AUTO;
        for (int i = 0; i < attrs.getAttributeCount(); i++) {
            String attr = attrs.getAttributeName(i);
            if (attr.equals("installLocation")) {
                installLocation = attrs.getAttributeIntValue(i,
                        PackageInfo.INSTALL_LOCATION_AUTO);
                break;
            }
        }
        return new PackageLite(pkgName.intern(), installLocation);
    }

    /**
     * Temporary.
     */
+2 −1
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.internal.app;

import android.net.Uri;
import android.os.ParcelFileDescriptor;
import android.content.pm.PackageInfoLite;

interface IMediaContainerService {
    String copyResourceToContainer(in Uri packageURI,
@@ -25,5 +26,5 @@ interface IMediaContainerService {
                String key, String resFileName);
    boolean copyResource(in Uri packageURI,
                in ParcelFileDescriptor outStream);
    int getRecommendedInstallLocation(in Uri fileUri);
    PackageInfoLite getMinimalPackageInfo(in Uri fileUri);
}
 No newline at end of file
Loading