トラッキング コード

Showing posts with label android frameworks. Show all posts
Showing posts with label android frameworks. Show all posts

11/04/2013

Andoird 4.4 KitKat StatusBar



SystemServer

We can hide StatusBar, settiing of "config.disable_systemui" .

https://android.googlesource.com/platform/frameworks/base/+/android-4.4_r1/services/java/com/android/server/SystemServer.java
        boolean disableSystemUI = SystemProperties.getBoolean("config.disable_systemui", false);

            if (!disableSystemUI) {
                try {
                    Slog.i(TAG, "Status Bar");
                    statusBar = new StatusBarManagerService(context, wm);
                    ServiceManager.addService(Context.STATUS_BAR_SERVICE, statusBar);
                } catch (Throwable e) {
                    reportWtf("starting StatusBarManagerService", e);
                }
            }


SystemUi

Delete "tablet" of folder. so not be used on JB!!

https://android.googlesource.com/platform/frameworks/base/+/android-4.4_r1/packages/SystemUI/src/com/android/systemui/statusbar/

7/28/2013

About AppOps in Android 4.3

Android 4.3 added "AppOps" whitch is like permission manager.


Points


  • added AppOpsManager, AppOpsService in the frameworks(Java Layer).
  • If you would like to use "AppOps", you can called getSystemService(Context.LAYOUT_INFLATER_SERVICE).
  • Each "Service" in frameworks decide to run operation, by obtaining a setting from the AppOpsService,
If you want to know more info, you should do grep "AppOpsManager.MODE_ALLOWED / MODE_IGNORED" in AOSP.




Create "AppOpsService" instance

AppOpsService is created in ActivityManagerService's constructor.

    private ActivityManagerService() {
        File systemDir = new File(dataDir, "system");
            :
        mAppOpsService = new AppOpsService(new File(systemDir, "appops.xml"));
            :
    }



Setting data of AppOpsManager

Setting data of AppOps is saved to xml file. Xml file is named "appops.xml". It is saved under the System directory.

public class AppOpsService extends IAppOpsService.Stub {
    public AppOpsService(File storagePath) {
        mFile = new AtomicFile(storagePath);
        mHandler = new Handler();
        readState();
    }

    void readState() {

    }
    void writeState() {

    }
}

Ckeck it

You should check many source in AOPS(android-4.3_r2.1).
Settings application
packages/apps/Settings/src/com/android/settings/applications
- AppOpsCategory.java
- AppOpsDetails.java
- AppOpsState.java
- AppOpsSummary.java


Frameworks
frameworks/base/core/java/android/app/ContextImpl.java
frameworks/base/core/java/android/app/AppOpsManager.java
frameworks/base/services/java/com/android/server/AppOpsService.java
frameworks/base/services/java/com/android/server/am/ActivityManagerService.java


8/30/2012

Never be called Application#onTerminate()


I checked up that Application(not Activity) has module of handling "stopped / resumed".
There was no explicit modules that are called from the frameworks.


So, What is Application#onTerminate()? Where is called in frameworks?
Are described in the Android Developers.

http://developer.android.com/reference/android/app/Application.html#onTerminate()

This method is for use in emulated process environments. It will never be called on a production Android device, where processes are removed by simply killing them; no user code (including this callback) is executed when doing so.

This Module will be present for what?

I do "grep" in Android frameworks, it is called from ActivityThread.java.

                case EXIT_APPLICATION:
                    if (mInitialApplication != null) {
                        mInitialApplication.onTerminate();
                    }
                    Looper.myLooper().quit();
                    break;


When ActivityThread#scheduleExit() send message, this process is called.

2 module in ActivityManagerService.java is called ActivityThread#scheduleExit()。


private final boolean attachApplicationLocked(IApplicationThread thread, int pid)
final void trimApplications()

Cord in module.
                    if (app.pid > 0 && app.pid != MY_PID) {
                        EventLog.writeEvent(EventLogTags.AM_KILL, app.pid,
                                app.processName, app.setAdj, "empty");
                        Process.killProcessQuiet(app.pid);
                    } else {
                        try {
                            app.thread.scheduleExit();
                        } catch (Exception e) {
                            // Ignore exceptions.
                        }
                    }
If the following case to call ActivityThread#scheduleExit().
  • PID is under "0"
  • PID is MY_PID(= System Process)


When Application is same "System Process", called ActivityThread#scheduleExit().
So, It is not application of "same System Process"...

7/01/2012

Phone mode or Tablet mode in Android 4.1 Jelly Bean?




Android 4.1 Jelly Bean has Phone UI Mode and Tablet UI Mode, so same ICS.
How to change Phone / Tablet in Android Frameworks ?

If you have Android SDK Api 16, you can notice source code!!

Definition of UI Mode

Check in PhoneWindowManager#setInitialDisplaySize.

\sources\android-16\com\android\internal\policy\impl\PhoneWindowManager.java

        // SystemUI (status bar) layout policy
        int shortSizeDp = shortSize
                * DisplayMetrics.DENSITY_DEFAULT
                / DisplayMetrics.DENSITY_DEVICE;

        if (shortSizeDp < 600) {
            // 0-599dp: "phone" UI with a separate status & navigation bar
            mHasSystemNavBar = false;
            mNavigationBarCanMove = true;
        } else if (shortSizeDp < 720) {
            // 600-719dp: "phone" UI with modifications for larger screens
            mHasSystemNavBar = false;
            mNavigationBarCanMove = false;
        } else {
            // 720dp: "tablet" UI with a single combined status & navigation bar
            mHasSystemNavBar = true;
            mNavigationBarCanMove = false;
        }

        if (!mHasSystemNavBar) {
            mHasNavigationBar = mContext.getResources().getBoolean(
                    com.android.internal.R.bool.config_showNavigationBar);
            // Allow a system property to override this. Used by the emulator.
            // See also hasNavigationBar().
            String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
            if (! "".equals(navBarOverride)) {
                if      (navBarOverride.equals("1")) mHasNavigationBar = false;
                else if (navBarOverride.equals("0")) mHasNavigationBar = true;
            }
        } else {
            mHasNavigationBar = false;
        } 
PhoneWindowManager has been changed from ICS.
Tablet UI mode need 720dp!!

2/17/2012

Disable Preinstall Application , Android 4.0.3



Can disable PreInstall Application in Settings->App->App info.
But limited PreInstall.

See Source in Android-4.0.3_r1.

packages\apps\Settings\src\com\android\settings\applications
- InstalledAppDetails.java

    private void initUninstallButtons() {
        mUpdatedSysApp = (mAppEntry.info.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0;
        boolean enabled = true;
        if (mUpdatedSysApp) {
            mUninstallButton.setText(R.string.app_factory_reset);
        } else {
            if ((mAppEntry.info.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
                enabled = false;
                if (SUPPORT_DISABLE_APPS) {
                    try {
                        // Try to prevent the user from bricking their phone
                        // by not allowing disabling of apps signed with the
                        // system cert and any launcher app in the system.
                        PackageInfo sys = mPm.getPackageInfo("android",
                                PackageManager.GET_SIGNATURES);
                        Intent intent = new Intent(Intent.ACTION_MAIN);
                        intent.addCategory(Intent.CATEGORY_HOME);
                        intent.setPackage(mAppEntry.info.packageName);
                        List homes = mPm.queryIntentActivities(intent, 0);
                        if ((homes != null && homes.size() > 0) ||
                                (mPackageInfo != null && mPackageInfo.signatures != null &&
                                        sys.signatures[0].equals(mPackageInfo.signatures[0]))) {
                            // Disable button for core system applications.
                            mUninstallButton.setText(R.string.disable_text);
                        } else if (mAppEntry.info.enabled) {
                            mUninstallButton.setText(R.string.disable_text);
                            enabled = true;
                        } else {
                            mUninstallButton.setText(R.string.enable_text);
                            enabled = true;
                        }
                    } catch (PackageManager.NameNotFoundException e) {
                        Log.w(TAG, "Unable to get package info", e);
                    }
                }
            } else {
                mUninstallButton.setText(R.string.uninstall_text);
            }
        }
        // If this is a device admin, it can't be uninstall or disabled.
        // We do this here so the text of the button is still set correctly.
        if (mDpm.packageHasActiveAdmins(mPackageInfo.packageName)) {
            enabled = false;
        }
        mUninstallButton.setEnabled(enabled);
        if (enabled) {
            // Register listener
            mUninstallButton.setOnClickListener(this);
        }
    }


The following System applications can not be disabled.
- Update from Market.
- Application has Activity with Intent.CATEGORY_HOME.(= Launcher Application)
- Application has same signature of System. ( = System Application)



If you set to disable, Application Icon in App List do not show.

2/05/2012

ScreenShot in ICS Android frameworks

Screenshot Proccess in Android Frameworks

Call interceptKeyBeforeQueueing from Navite Layer InputDispatcher 
InputManager#interceptKeyBeforeQueueing
 - PhoneWindowManager#interceptKeyBeforeQueueing
  - interceptKeyBeforeQueueing
    - interceptScreenshotChord()
      - mScreenshotChordLongPress#run
        - takeScreenshot()
            TakeScreenshotService of new Service in SystemUI
            - run()
              - GlobalScreenshot#takeScreenshot
                called Surface.screenshot to get Bitmap
                Animation and Save Screen Image!!


Check source!!


\frameworks\base\services\input
- InputDispatcher.cpp
- InputManager.cpp

\frameworks\base\policy\src\com\android\internal\policy\impl
- PhoneWindowManager.java

\frameworks\base\packages\SystemUI\src\com\android\systemui\screenshot
- GlobalScreenshot.java
- TakeScreenshotService.java



1/29/2012

NavigationBar / Virtual buttons in the System Bar

NavigationBar

NavigationBar is Virtual buttons in the System Bar.




Implement of NavigationBar

NavigationBar has been implemented as part of SystemUI / StatusBar.
Show PhoneStatusBar.java.

\frameworks\base\packages\SystemUI\src\com\android\systemui\statusbar\phone
- PhoneStatusBar.java

try {
            boolean showNav = mWindowManager.hasNavigationBar();
            if (showNav) {
                mNavigationBarView =
                    (NavigationBarView) View.inflate(context, R.layout.navigation_bar, null);

                mNavigationBarView.setDisabledFlags(mDisabled);
            }
        } catch (RemoteException ex) {
            // no window manager? good luck with that
        }

It is just View!!

Layout file is
\frameworks\base\packages\SystemUI\res\layout
- navigation_bar.xml



Case of Tablet devices.

\frameworks\base\packages\SystemUI\src\com\android\systemui\statusbar\tablet
- TabletStatusBar.java

try {
            // Sanity-check that someone hasn't set up the config wrong and asked for a navigation
            // bar on a tablet that has only the system bar
            if (mWindowManager.hasNavigationBar()) {
                throw new RuntimeException(
                        "Tablet device cannot show navigation bar and system bar");
            }
        } catch (RemoteException ex) {
        }

If Tablet devices has NavigationBar,occurs RuntimeException!!
Tablet devices do not implement NavigationBar.


NavigationBar is enable or Diseble ?

Show PhoneWindowManager#setInitialDisplaySize().


// Determine whether the status bar can hide based on the size
        // of the screen.  We assume sizes > 600dp are tablets where we
        // will use the system bar.
        int shortSizeDp = shortSize
                * DisplayMetrics.DENSITY_DEFAULT
                / DisplayMetrics.DENSITY_DEVICE;
        mStatusBarCanHide = shortSizeDp < 600;
        mStatusBarHeight = mContext.getResources().getDimensionPixelSize(
                mStatusBarCanHide
                ? com.android.internal.R.dimen.status_bar_height
                : com.android.internal.R.dimen.system_bar_height);

        mHasNavigationBar = mContext.getResources().getBoolean(
                com.android.internal.R.bool.config_showNavigationBar);
        // Allow a system property to override this. Used by the emulator.
        // See also hasNavigationBar().
        String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
        if (! "".equals(navBarOverride)) {
            if      (navBarOverride.equals("1")) mHasNavigationBar = false;
            else if (navBarOverride.equals("0")) mHasNavigationBar = true;
        }
To see the value of com.android.internal.R.bool.config_showNavigationBar.
It is defined in following xml

 \frameworks\base\core\res\res\values - config.xml


<!-- Whether a software navigation bar should be shown. NOTE: in the future this may be
         autodetected from the Configuration. -->
    <bool name="config_showNavigationBar">false</bool>


Standard ICS is not shown as a NavigationBar.So, Check of device folder.

\device\samsung\tuna\overlay\frameworks\base\core\res\res\values
- config.xml
This value Will be displayed on GalaxyNexus.


Key Event of NavigationBar

If Buttom of home/back is touched, send inputEvent from Java Layer to Native Layer.
KeyButtonView#sendEvent
 - WindowManagerService#injectInputEventNoWait
   - InputManager#injectInputEvent
     - InputManager#nativeInjectInputEvent
       - android_server_InputManager_nativeInjectInputEvent
       - InputDispatcher#injectInputEvent




1/27/2012

Phone mode or Tablet mode in Ice Cream Sandwich ?

ICS has Phone UI Mode and Tablet UI Mode.
How to change Phone / Tablet in Android Frameworks ?


Definition of UI Mode

you can find in wake up Sequence.


ServerThread#run()
- WindowManagerService#displayReady
- PhoneWindowManagerService#setInitialDisplaySize


Check in PhoneWindowManagerService#setInitialDisplaySize.


// Determine whether the status bar can hide based on the size
        // of the screen.  We assume sizes > 600dp are tablets where we
        // will use the system bar.
        int shortSizeDp = shortSize
                * DisplayMetrics.DENSITY_DEFAULT
                / DisplayMetrics.DENSITY_DEVICE;
        mStatusBarCanHide = shortSizeDp < 600;


DisplayMetrics.DENSITY_DEFAULT is define in DisplayMetrics.java

/**
     * Standard quantized DPI for medium-density screens.
     */
    public static final int DENSITY_MEDIUM = 160;

    /**
     * The reference density used throughout the system.
     */
    public static final int DENSITY_DEFAULT = DENSITY_MEDIUM;

    /**
     * The device's density.
     * @hide becase eventually this should be able to change while
     * running, so shouldn't be a constant.
     */
    public static final int DENSITY_DEVICE = getDeviceDensity();

    private static int getDeviceDensity() {
        // qemu.sf.lcd_density can be used to override ro.sf.lcd_density
        // when running in the emulator, allowing for dynamic configurations.
        // The reason for this is that ro.sf.lcd_density is write-once and is
        // set by the init process when it parses build.prop before anything else.
        return SystemProperties.getInt("qemu.sf.lcd_density",
                SystemProperties.getInt("ro.sf.lcd_density", DENSITY_DEFAULT));
    }


Case of Crespo(Nexus s),
swWidth = 480
  ro.sf.lcd_density=240
  shortSizeDp = 480 * 160 / 240 = 320
Crespo has Phone UI mode.


Case of maguro(Galaxy Nexus),
swWidth = 720
  ro.sf.lcd_density=320
  shortSizeDp = 720 * 160 / 320 = 360
Maguro has Phone UI mode.


If you want to use Maguro with Tablet UI Mode, change lcd_density from 320 to 160.
swWidth = 720
  ro.sf.lcd_density=160
  shortSizeDp = 720 * 160 / 160 = 720



Check !!

\frameworks\base\policy\src\com\android\internal\policy\impl
- PhoneWindowManagerService.java

\frameworks\base\core\java\android\util
- DisplayMetrics.java

\frameworks\base\packages\SystemUI\src\com\android\systemui\statusbar
- all directory ( StatusBar / SystemBar)

1/21/2012

CPU Usage

how to display of CPU usage

Settings -> Developer Options -> Show CPU usage

Screen overlay showing current CPU usage.

Setting CPU Usage in frameworks

DevelopmentSettings#onPreferenceTreeClick
- writeCpuUsageOptions()
  - startService "com.android.systemui.LoadAverageService" of SysttemUI.
  - LoadAverageService#onCreate()
    - new LoadView extends ProcessStats
        - new Stats
    - WindowManager#addView() with Overlay layer of SECURE_SYSTEM_OVERLAY_LAYER
        - WindowManagerImpl#addView
            - ViewRootImpl#setView
                - IWindowSession#add
                    - Session#add
                        - WindowManagerService#addWindow


check sorce file

\packages\apps\Settings\src\com\android\settings
- DevelopmentSettings.java

\frameworks\base\packages\SystemUI\src\com\android\systemui
- LoadAverageService.java

\frameworks\base\policy\src\com\android\internal\policy\impl
- PhoneWindowManager.java

\frameworks\base\core\java\com\android\internal\os
- ProcessStats.java



8/17/2011

Analysis of the Android frameworks : Screen Lock Settings

OS version

Android OS 2.3.5_r1


Screen Lock Settings

'Screen unlock security' lock screen can be set from Settings.apk.
Password and pattern information that used unlock screen is managed by 'LockPatternUtils'.



LockPatternUtils class overview

Generate an SHA-1(and MD5) hash for the password / pattern.
Write the hash to file.
Check to see if a password matches the saved password / pattern.
Save password quality to DevicePolicyManager.




8/03/2011

Analysis of the Android frameworks part1 : PackageManager

OS version

Android OS 2.3.5_r1

PackageManager class overview

Class for retrieving various kinds of information related to the application packages that are currently installed on the device.


PackageManagerService class overview

  • Load apks from "system/app/" directory.
  • Load apks from "data/data/" directory (= download apks).
  • Move package to SD/device.
  • Hold information about installed package .
  • Hold information about Features this devices supports that were read from the xml file.



Note

  • ApplicationPackageManager extended PackageManager  is inner class of CotextImpl.
  • ApplicationPackageManager has a interface IPackageManager.
  • PackageManagerService is the implementation class IPackageManager#stub.
  • PackageManagerService holds information about all packages.







information about Features this devices supports

Feature information read from xml file.

void readPermissions() {
        // Read permissions from .../etc/permission directory.
        File libraryDir = new File(Environment.getRootDirectory(), "etc/permissions");

               : 
               : 

        // Iterate over the files in the directory and scan .xml files
        for (File f : libraryDir.listFiles()) {
            // We'll read platform.xml last
            if (f.getPath().endsWith("etc/permissions/platform.xml")) {
                continue;
            }

               : 
               : 

            readPermissionsFromXml(f);
        }

        // Read permissions from .../etc/permissions/platform.xml last so it will take precedence
        final File permFile = new File(Environment.getRootDirectory(),
                "etc/permissions/platform.xml");
        readPermissionsFromXml(permFile);
    }

    private void readPermissionsFromXml(File permFile) {
               : 
               : 
                } else if ("feature".equals(name)) {
                    String fname = parser.getAttributeValue(null, "name");
                    if (fname == null) {
                        Slog.w(TAG, " without name at "
                                + parser.getPositionDescription());
                    } else {
                        //Log.i(TAG, "Got feature " + fname);
                        FeatureInfo fi = new FeatureInfo();
                        fi.name = fname;
                        mAvailableFeatures.put(fname, fi);
                    }
                    XmlUtils.skipCurrentTag(parser);
                    continue;

                } else {
               : 
               : 
    }


You can see the following from the above sources.
  • read xmls in "system/etc/permissions" directory.
  • read "system/etc/permissions/platform.xml".
  • holds information to put to mAvailableFeatures of private member in class. 



PackageManagerService read xmls from system folder, and put to mAvailableFeatures.
How does xml  built into system.img?
Please view the build environment Nexus S Android_2.3.5_r1, so you can find makefile which are written the following.

file : device/samsung/crespo/device_base.mk

# These are the hardware-specific features
PRODUCT_COPY_FILES += \
 frameworks/base/data/etc/handheld_core_hardware.xml:system/etc/permissions/handheld_core_hardware.xml \
 frameworks/base/data/etc/android.hardware.camera.flash-autofocus.xml:system/etc/permissions/android.hardware.camera.flash-autofocus.xml \
 frameworks/base/data/etc/android.hardware.camera.front.xml:system/etc/permissions/android.hardware.camera.front.xml \
 frameworks/base/data/etc/android.hardware.location.gps.xml:system/etc/permissions/android.hardware.location.gps.xml \
 frameworks/base/data/etc/android.hardware.wifi.xml:system/etc/permissions/android.hardware.wifi.xml \
 frameworks/base/data/etc/android.hardware.sensor.proximity.xml:system/etc/permissions/android.hardware.sensor.proximity.xml \
 frameworks/base/data/etc/android.hardware.sensor.light.xml:system/etc/permissions/android.hardware.sensor.light.xml \
 frameworks/base/data/etc/android.hardware.sensor.gyroscope.xml:system/etc/permissions/android.hardware.sensor.gyroscope.xml \
 frameworks/base/data/etc/android.hardware.touchscreen.multitouch.jazzhand.xml:system/etc/permissions/android.hardware.touchscreen.multitouch.jazzhand.xml \
 frameworks/base/data/etc/android.hardware.nfc.xml:system/etc/permissions/android.hardware.nfc.xml \
 frameworks/base/data/etc/android.software.sip.voip.xml:system/etc/permissions/android.software.sip.voip.xml \
 frameworks/base/data/etc/android.hardware.usb.accessory.xml:system/etc/permissions/android.hardware.usb.accessory.xml \
 packages/wallpapers/LivePicker/android.software.live_wallpaper.xml:system/etc/permissions/android.software.live_wallpaper.xml


it is mean "Copy from 'system/etc/permissions/XXX.xml to 'frameworks/base/data/etc/XXXX.xml".
When you add a device function on its own, may be added here.