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;
}
}
Aggregations