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

Commit 0fe40a0e authored by Brint E. Kriebel's avatar Brint E. Kriebel
Browse files

Merge branch 'cm-11.0' into stable/cm-11.0

parents 9bb2da13 84704e53
Loading
Loading
Loading
Loading
+0 −17
Original line number Diff line number Diff line
@@ -20,7 +20,6 @@ import static android.net.TrafficStats.MB_IN_BYTES;

import android.content.ContentResolver;
import android.content.Context;
import android.hardware.usb.UsbManager;
import android.os.Environment;
import android.os.Handler;
import android.os.Looper;
@@ -381,22 +380,6 @@ public class StorageManager {
       }
    }

    /**
     * Switch USB Mass Storage (UMS) on the device.
     *
     * @hide
     */
    public void setUsbMassStorageEnabled(boolean enable) {
        UsbManager manager = new UsbManager(null, null);
        if (enable && manager.isFunctionEnabled(UsbManager.USB_FUNCTION_MASS_STORAGE)) {
            if(!isUsbMassStorageEnabled()) {
                enableUsbMassStorage();
            }
        } else if (isUsbMassStorageEnabled()) {
            disableUsbMassStorage();
        }
    }

    /**
     * Enables USB Mass Storage (UMS) on the device.
     *
+309 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2013-2014 The CyanogenMod 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 com.android.internal.util.cm;

import android.app.WallpaperManager;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.ThemeUtils;
import android.content.res.AssetManager;
import android.content.res.Resources;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Point;
import android.net.Uri;
import android.provider.ThemesContract;
import android.provider.ThemesContract.ThemesColumns;
import android.text.TextUtils;
import android.util.Log;
import android.webkit.URLUtil;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;

import libcore.io.IoUtils;

public class ImageUtils {
    private static final String TAG = ImageUtils.class.getSimpleName();

    private static final String ASSET_URI_PREFIX = "file:///android_asset/";
    private static final int DEFAULT_IMG_QUALITY = 100;

    /**
     * Gets the Width and Height of the image
     *
     * @param inputStream The input stream of the image
     *
     * @return A point structure that holds the Width and Height (x and y)/*"
     */
    public static Point getImageDimension(InputStream inputStream) {
        if (inputStream == null) {
            throw new IllegalArgumentException("'inputStream' cannot be null!");
        }
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeStream(inputStream, null, options);
        Point point = new Point(options.outWidth,options.outHeight);
        return point;
    }

    /**
     * Crops the input image and returns a new InputStream of the cropped area
     *
     * @param inputStream The input stream of the image
     * @param imageWidth Width of the input image
     * @param imageHeight Height of the input image
     * @param inputStream Desired Width
     * @param inputStream Desired Width
     *
     * @return a new InputStream of the cropped area/*"
     */
    public static InputStream cropImage(InputStream inputStream, int imageWidth, int imageHeight,
            int outWidth, int outHeight) throws IllegalArgumentException {
        if (inputStream == null){
            throw new IllegalArgumentException("inputStream cannot be null");
        }

        if (imageWidth <= 0 || imageHeight <= 0) {
            throw new IllegalArgumentException(
                    String.format("imageWidth and imageHeight must be > 0: imageWidth=%d" +
                            " imageHeight=%d", imageWidth, imageHeight));
        }

        if (outWidth <= 0 || outHeight <= 0) {
            throw new IllegalArgumentException(
                    String.format("outWidth and outHeight must be > 0: outWidth=%d" +
                            " outHeight=%d", imageWidth, outHeight));
        }

        int scaleDownSampleSize = Math.min(imageWidth / outWidth, imageHeight / outHeight);
        if (scaleDownSampleSize > 0) {
            imageWidth /= scaleDownSampleSize;
            imageHeight /= scaleDownSampleSize;
        } else {
            float ratio = (float) outWidth / outHeight;
            if (imageWidth < imageHeight * ratio) {
                outWidth = imageWidth;
                outHeight = (int) (outWidth / ratio);
            } else {
                outHeight = imageHeight;
                outWidth = (int) (outHeight * ratio);
            }
        }
        int left = (imageWidth - outWidth) / 2;
        int top = (imageHeight - outHeight) / 2;
        InputStream compressed = null;
        try {
            BitmapFactory.Options options = new BitmapFactory.Options();
            if (scaleDownSampleSize > 1) {
                options.inSampleSize = scaleDownSampleSize;
            }
            Bitmap bitmap = BitmapFactory.decodeStream(inputStream, null, options);
            if (bitmap == null) {
                return null;
            }
            Bitmap cropped = Bitmap.createBitmap(bitmap, left, top, outWidth, outHeight);
            ByteArrayOutputStream tmpOut = new ByteArrayOutputStream(2048);
            if (cropped.compress(Bitmap.CompressFormat.PNG, DEFAULT_IMG_QUALITY, tmpOut)) {
                byte[] outByteArray = tmpOut.toByteArray();
                compressed = new ByteArrayInputStream(outByteArray);
            }
        } catch (Exception e) {
            Log.e(TAG, "Exception " + e);
        }
        return compressed;
    }

    /**
     * Crops the lock screen image and returns a new InputStream of the cropped area
     *
     * @param pkgName Name of the theme package
     * @param context The context
     *
     * @return a new InputStream of the cropped image/*"
     */
    public static InputStream getCroppedKeyguardStream(String pkgName, Context context)
            throws IllegalArgumentException {
        if (TextUtils.isEmpty(pkgName)) {
            throw new IllegalArgumentException("'pkgName' cannot be null or empty!");
        }
        if (context == null) {
            throw new IllegalArgumentException("'context' cannot be null!");
        }

        InputStream cropped = null;
        InputStream stream = null;
        try {
            stream = getOriginalKeyguardStream(pkgName, context);
            if (stream == null) {
                return null;
            }
            Point point = getImageDimension(stream);
            IoUtils.closeQuietly(stream);
            if (point == null || point.x == 0 || point.y == 0) {
                return null;
            }
            WallpaperManager wm = WallpaperManager.getInstance(context);
            int outWidth = wm.getDesiredMinimumWidth();
            int outHeight = wm.getDesiredMinimumHeight();
            stream = getOriginalKeyguardStream(pkgName, context);
            if (stream == null) {
                return null;
            }
            cropped = cropImage(stream, point.x, point.y, outWidth, outHeight);
        } catch (Exception e) {
            Log.e(TAG, "Exception " + e);
        } finally {
            IoUtils.closeQuietly(stream);
        }
        return cropped;
    }

    /**
     * Crops the wallpaper image and returns a new InputStream of the cropped area
     *
     * @param pkgName Name of the theme package
     * @param context The context
     *
     * @return a new InputStream of the cropped image/*"
     */
    public static InputStream getCroppedWallpaperStream(String pkgName, Context context) {
        if (TextUtils.isEmpty(pkgName)) {
            throw new IllegalArgumentException("'pkgName' cannot be null or empty!");
        }
        if (context == null) {
            throw new IllegalArgumentException("'context' cannot be null!");
        }

        InputStream cropped = null;
        InputStream stream = null;
        try {
            stream = getOriginalWallpaperStream(pkgName, context);
            if (stream == null) {
                return null;
            }
            Point point = getImageDimension(stream);
            IoUtils.closeQuietly(stream);
            if (point == null || point.x == 0 || point.y == 0) {
                return null;
            }
            WallpaperManager wm = WallpaperManager.getInstance(context);
            int outWidth = wm.getDesiredMinimumWidth();
            int outHeight = wm.getDesiredMinimumHeight();
            stream = getOriginalWallpaperStream(pkgName, context);
            if (stream == null) {
                return null;
            }
            cropped = cropImage(stream, point.x, point.y, outWidth, outHeight);
        } catch (Exception e) {
            Log.e(TAG, "Exception " + e);
        } finally {
            IoUtils.closeQuietly(stream);
        }
        return cropped;
    }

    private static InputStream getOriginalKeyguardStream(String pkgName, Context context) {
        if (TextUtils.isEmpty(pkgName) || context == null) {
            return null;
        }

        InputStream inputStream = null;
        try {
            //Get input WP stream from the theme
            Context themeCtx = context.createPackageContext(pkgName,
                    Context.CONTEXT_IGNORE_SECURITY);
            AssetManager assetManager = themeCtx.getAssets();
            String wpPath = ThemeUtils.getLockscreenWallpaperPath(assetManager);
            if (wpPath == null) {
                Log.w(TAG, "Not setting lockscreen wp because wallpaper file was not found.");
            } else {
                inputStream = ThemeUtils.getInputStreamFromAsset(themeCtx,
                        ASSET_URI_PREFIX + wpPath);
            }
        } catch (Exception e) {
            Log.e(TAG, "There was an error setting lockscreen wp for pkg " + pkgName, e);
        }
        return inputStream;
    }

    private static InputStream getOriginalWallpaperStream(String pkgName, Context context) {
        if (TextUtils.isEmpty(pkgName) || context == null) {
            return null;
        }

        InputStream inputStream = null;
        String selection = ThemesContract.ThemesColumns.PKG_NAME + "= ?";
        String[] selectionArgs = {pkgName};
        Cursor c = context.getContentResolver().query(ThemesColumns.CONTENT_URI,
                null, selection,
                selectionArgs, null);
        if (c == null || c.getCount() < 1) {
            if (c != null) c.close();
            return null;
        } else {
            c.moveToFirst();
        }

        try {
            Context themeContext = context.createPackageContext(pkgName,
                    Context.CONTEXT_IGNORE_SECURITY);
            boolean isLegacyTheme = c.getInt(
                    c.getColumnIndex(ThemesColumns.IS_LEGACY_THEME)) == 1;
            if (!isLegacyTheme) {
                String wallpaper = c.getString(
                        c.getColumnIndex(ThemesColumns.WALLPAPER_URI));
                if (wallpaper != null) {
                    if (URLUtil.isAssetUrl(wallpaper)) {
                        inputStream = ThemeUtils.getInputStreamFromAsset(themeContext, wallpaper);
                    } else {
                        inputStream = context.getContentResolver().openInputStream(
                                Uri.parse(wallpaper));
                    }
                } else {
                    // try and get the wallpaper directly from the apk if the URI was null
                    Context themeCtx = context.createPackageContext(pkgName,
                            Context.CONTEXT_IGNORE_SECURITY);
                    AssetManager assetManager = themeCtx.getAssets();
                    String wpPath = ThemeUtils.getWallpaperPath(assetManager);
                    if (wpPath == null) {
                        Log.e(TAG, "Not setting wp because wallpaper file was not found.");
                    } else {
                        inputStream = ThemeUtils.getInputStreamFromAsset(themeCtx,
                                ASSET_URI_PREFIX + wpPath);
                    }
                }
            } else {
                Resources resources = context.getResources();
                PackageInfo pi = context.getPackageManager().getPackageInfo(pkgName, 0);

                if (pi.legacyThemeInfos != null && pi.legacyThemeInfos.length > 0) {
                    inputStream =
                            resources.openRawResource(pi.legacyThemeInfos[0].wallpaperResourceId);
                }
            }
        } catch (Exception e) {
            Log.e(TAG, "getWallpaperStream: " + e);
        } finally {
            c.close();
        }

        return inputStream;
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@
    android:gravity="start|center_vertical"
    android:drawablePadding="8dp"
    android:paddingStart="8dp"
    android:textColor="#ccc"
    android:textColor="@color/notification_action_text_color"
    android:textSize="14dp"
    android:singleLine="true"
    android:ellipsize="end"
+9 −0
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@
  <string name="permlab_preventpower">Verhoed krag knoppie</string>
  <string name="permdesc_preventpower">Laat die program toe om die krag knoppie se gebruik te verander.</string>
  <string name="permlab_sendMockSms">Stuur skyn-SMS boodskappe</string>
  <string name="permdesc_sendMockSms">Laat die program toe om skyn-SMS boodskappe stuur. Dit laat \'n program toe om \'n SMS te stuur na betroubare programme. Kwaadwillige programme kan boodskappe voortdurend stuur, dit sal die kennisgewings stelsel blokkeer en die gebruiker ontwrig.</string>
  <string name="storage_sd_dock_card">Dok SD kaart</string>
  <string name="app_killed_message">Program beëindig</string>
  <string name="global_action_reboot">Herlaai</string>
@@ -66,6 +67,10 @@
  <string name="perf_profile_perf">Werkverrigting</string>
  <string name="permlab_interceptSmsSent">Onderskep uitgaande SMS</string>
  <string name="permdesc_interceptSmsSent">Laat \'n program toe om uitgaande SMS boodskappe te onderskep. Kwaadwillige programme kan die reg misbruik om uitgaande SMS boodskappe te verhoed.</string>
  <string name="permlab_receiveProtectedSms">ontvang beskermde SMS</string>
  <string name="permdesc_receiveProtectedSms">Laat die program toe om \'n beskermde inkomende SMS te ontvang.</string>
  <string name="permlab_modifyProtectedSmsList">verander beskermde SMS lys</string>
  <string name="permdesc_modifyProtectedSmsList">Laat die program toe om die beskermde SMS adres lys te verander.</string>
  <string name="permlab_resetBatteryStats">battery statistieke terugstel</string>
  <string name="permdesc_resetBatteryStats">Laat \'n program om die huidige lae-vlak battery gebruik data terugtestel.</string>
  <string name="permgrouplab_security">Sekuriteit</string>
@@ -84,6 +89,10 @@
  <string name="permdesc_setKeyguardWallpaper">Laat \'n program toe om die slotskerm agtergrond te verander.</string>
  <string name="permlab_useHardwareFramework">gebruik hardeware raamwerk</string>
  <string name="permdesc_useHardwareFramework">Laat program toegang tot die CM hardeware raamwerk.</string>
  <string name="permlab_keyguardApplicationWidget">stel slot skerm program legkaart</string>
  <string name="permdesc_keyguardApplicationWidget">Laat \'n program toe om \'n legstuk op die slot skerm te plaas.</string>
  <string name="permlab_interceptPackageLaunch">onderskep die begin van \'n program</string>
  <string name="permdesc_interceptPackageLaunch">Laat toe dat \'n program die begin van ander programme onderskep</string>
  <string name="immersive_mode_confirmation_bottom">Skyf van die onderkant om vol skerm toe te maak.</string>
  <string name="app_ops_access_camera">toegang tot die kamera</string>
  <string name="app_ops_access_location">toegang tot jou ligging</string>
+2 −2
Original line number Diff line number Diff line
@@ -22,7 +22,7 @@
  <string name="profileNameHome">الصفحة الرئيسية</string>
  <string name="profileNameSilent">صامت</string>
  <string name="profileNameNight">ليلة</string>
  <string name="profileNameAutomobile">السيارات</string>
  <string name="profileNameAutomobile">السيارة</string>
  <string name="profileGroupPhone">الهاتف</string>
  <string name="profileGroupCalendar">التقويم</string>
  <string name="profileGroupGmail">Gmail</string>
@@ -48,7 +48,7 @@
  <string name="permlab_preventpower">منع زر الطاقة</string>
  <string name="permdesc_preventpower">يسمح التطبيق لتجاوز زر الطاقة</string>
  <string name="permlab_sendMockSms">إرسال رسائل زائفة قصيرة</string>
  <string name="storage_sd_dock_card">بطاقة SD مزيفة</string>
  <string name="storage_sd_dock_card">بطاقة ذاكرة في منصّة الإرساء</string>
  <string name="app_killed_message">التطبيق قد قتل</string>
  <string name="global_action_reboot">إعادة التشغيل</string>
  <string name="global_action_choose_profile">الشخصية</string>
Loading