Search in sources :

Example 1 with SharedRootFW

use of com.spazedog.lib.rootfw3.extenders.InstanceExtender.SharedRootFW in project mounts2sd by SpazeDog.

the class Preferences method getInstance.

public static Preferences getInstance(Context context) {
    synchronized (oClassLock) {
        Preferences tmpPreferences = oClassReference != null ? oClassReference.get() : null;
        Context tmpContext = oContextReference != null ? oContextReference.get() : null;
        if (tmpContext == null)
            oContextReference = new WeakReference<Context>((tmpContext = context.getApplicationContext()));
        if (tmpPreferences == null)
            oClassReference = new WeakReference<Preferences>((tmpPreferences = new Preferences()));
        if (tmpPreferences.mSharedPreferences.size() == 0) {
            tmpPreferences.mSharedPreferences.put("cache", tmpContext.getSharedPreferences("cache", 0x00000000));
            tmpPreferences.mSharedPreferences.put("persistent", tmpContext.getSharedPreferences("persistent", 0x00000000));
        }
        if (!oClassChecks.get("initiated.cache")) {
            String appid = tmpContext.getResources().getString(R.string.config_application_id);
            SharedPreferences sharedPreferences = tmpPreferences.mSharedPreferences.get("cache");
            if (!appid.equals("" + sharedPreferences.getInt("android.appId", 0)) || !new java.io.File("/boot.chk").exists()) {
                RootFW root = Root.initiate();
                Editor edit = sharedPreferences.edit();
                edit.clear();
                edit.putInt("android.appId", Integer.parseInt(appid));
                edit.commit();
                if (root.isConnected()) {
                    root.filesystem("/").addMount(new String[] { "remount", "rw" });
                    root.file("/boot.chk").write("1");
                    root.filesystem("/").addMount(new String[] { "remount", "ro" });
                } else {
                    ((SharedRootFW) root).addInstanceListener(new ConnectionListener() {

                        @Override
                        public void onConnectionEstablished(RootFW instance) {
                            instance.filesystem("/").addMount(new String[] { "remount", "rw" });
                            instance.file("/boot.chk").write("1");
                            instance.filesystem("/").addMount(new String[] { "remount", "ro" });
                            ((SharedRootFW) instance).removeInstanceListener(this);
                        }

                        @Override
                        public void onConnectionFailed(RootFW instance) {
                        }

                        @Override
                        public void onConnectionClosed(RootFW instance) {
                        }
                    });
                }
                Root.release();
            }
            oClassChecks.put("initiated.cache", true);
        }
        return tmpPreferences;
    }
}
Also used : Context(android.content.Context) SharedPreferences(android.content.SharedPreferences) WeakReference(java.lang.ref.WeakReference) SharedRootFW(com.spazedog.lib.rootfw3.extenders.InstanceExtender.SharedRootFW) ConnectionListener(com.spazedog.lib.rootfw3.RootFW.ConnectionListener) SharedPreferences(android.content.SharedPreferences) Editor(android.content.SharedPreferences.Editor) SharedRootFW(com.spazedog.lib.rootfw3.extenders.InstanceExtender.SharedRootFW) RootFW(com.spazedog.lib.rootfw3.RootFW)

Aggregations

Context (android.content.Context)1 SharedPreferences (android.content.SharedPreferences)1 Editor (android.content.SharedPreferences.Editor)1 RootFW (com.spazedog.lib.rootfw3.RootFW)1 ConnectionListener (com.spazedog.lib.rootfw3.RootFW.ConnectionListener)1 SharedRootFW (com.spazedog.lib.rootfw3.extenders.InstanceExtender.SharedRootFW)1 WeakReference (java.lang.ref.WeakReference)1