Example usage for android.content Context MODE_WORLD_WRITEABLE

List of usage examples for android.content Context MODE_WORLD_WRITEABLE

Introduction

In this page you can find the example usage for android.content Context MODE_WORLD_WRITEABLE.

Prototype

int MODE_WORLD_WRITEABLE

To view the source code for android.content Context MODE_WORLD_WRITEABLE.

Click Source Link

Document

File creation mode: allow all other applications to have write access to the created file.

Usage

From source file:com.geoffreybuttercrumbs.arewethereyet.ZonePicker.java

private void saveCoordinatesInPreferences(float latitudeSP, float longitudeSP, int radiusSP, String address) {
    SharedPreferences prefs = this.getSharedPreferences("AreWeThereYet", Context.MODE_WORLD_WRITEABLE);
    SharedPreferences.Editor prefsEditor = prefs.edit();
    for (int i = 5; i > 1; i--) {
        prefsEditor.putFloat(POINT_LATITUDE_KEY + i, prefs.getFloat(POINT_LATITUDE_KEY + (i - 1), 0));
        prefsEditor.putFloat(POINT_LONGITUDE_KEY + i, prefs.getFloat(POINT_LONGITUDE_KEY + (i - 1), 0));
        prefsEditor.putInt(POINT_RADIUS_KEY + i, prefs.getInt(POINT_RADIUS_KEY + (i - 1), 0));
        prefsEditor.putString(POINT_ADDRESS_KEY + i, prefs.getString(POINT_ADDRESS_KEY + (i - 1), ""));
    }//from  ww w.  j  a  v a  2  s . c om
    prefsEditor.putFloat(POINT_LATITUDE_KEY + 1, latitudeSP);
    prefsEditor.putFloat(POINT_LONGITUDE_KEY + 1, longitudeSP);
    prefsEditor.putInt(POINT_RADIUS_KEY + 1, radiusSP);
    prefsEditor.putString(POINT_ADDRESS_KEY + 1, address);
    prefsEditor.commit();
}

From source file:edu.umich.oasis.service.KVSSharedPrefs.java

@SuppressWarnings("deprecation")
public KVSSharedPrefs(Sandbox sandbox, String owningPackage, String callingPackage, String storeName,
        int mode) {
    mContext = OASISApplication.getInstance();
    mSandbox = sandbox;//from w w  w  .  java2 s  .  c  om
    mStoreName = storeName;
    mOwningPackage = mContext.checkPackageName(owningPackage);

    SharedPreferences sp = getPlatformSharedPrefs(storeName);
    mPrefs = NamespaceSharedPrefs.get(sp, TAINT_SET, TAINT);

    // Handle read and write permissions, as previously configured.
    boolean configReadPublic = mPrefs.getBoolean(CONFIG, CONFIG_PUBLIC_READABLE, false);
    boolean configWritePublic = mPrefs.getBoolean(CONFIG, CONFIG_PUBLIC_WRITABLE, false);

    if (localLOGD) {
        Log.d(TAG,
                String.format("Store '%s', owner '%s', caller '%s'", storeName, owningPackage, callingPackage));
    }
    // Are we trying to load this package's prefs, or something else?
    boolean isSamePackage = Objects.equals(owningPackage, callingPackage);

    // Set the readable and writable flags for this object...
    isReadable = isSamePackage || configReadPublic;
    isWritable = isSamePackage || configWritePublic;

    // ...And set the flags that will be written on update.
    canReadPublic = (mode & Context.MODE_WORLD_READABLE) != 0;
    canWritePublic = (mode & Context.MODE_WORLD_WRITEABLE) != 0;

    isClosed = false;
}

From source file:edu.umich.flowfence.service.KVSSharedPrefs.java

@SuppressWarnings("deprecation")
public KVSSharedPrefs(Sandbox sandbox, String owningPackage, String callingPackage, String storeName,
        int mode) {
    mContext = FlowfenceApplication.getInstance();
    mSandbox = sandbox;/*w  w  w . ja  v a  2  s . c  o  m*/
    mStoreName = storeName;
    mOwningPackage = mContext.checkPackageName(owningPackage);

    SharedPreferences sp = getPlatformSharedPrefs(storeName);
    mPrefs = NamespaceSharedPrefs.get(sp, TAINT_SET, TAINT);

    // Handle read and write permissions, as previously configured.
    boolean configReadPublic = mPrefs.getBoolean(CONFIG, CONFIG_PUBLIC_READABLE, false);
    boolean configWritePublic = mPrefs.getBoolean(CONFIG, CONFIG_PUBLIC_WRITABLE, false);

    if (localLOGD) {
        Log.d(TAG,
                String.format("Store '%s', owner '%s', caller '%s'", storeName, owningPackage, callingPackage));
    }
    // Are we trying to load this package's prefs, or something else?
    boolean isSamePackage = Objects.equals(owningPackage, callingPackage);

    // Set the readable and writable flags for this object...
    isReadable = isSamePackage || configReadPublic;
    isWritable = isSamePackage || configWritePublic;

    // ...And set the flags that will be written on update.
    canReadPublic = (mode & Context.MODE_WORLD_READABLE) != 0;
    canWritePublic = (mode & Context.MODE_WORLD_WRITEABLE) != 0;

    isClosed = false;
}

From source file:com.geoffreybuttercrumbs.arewethereyet.DrawerFragment.java

private int touchSaveIndex(int mod) {
    SharedPreferences prefs = getActivity().getSharedPreferences("AreWeThereYet", Context.MODE_WORLD_WRITEABLE);
    SharedPreferences.Editor prefsEditor = prefs.edit();
    prefsEditor.putInt(POINT_SAVED_INDEX, (prefs.getInt(POINT_SAVED_INDEX, 0) + mod));
    prefsEditor.commit();/*from   w  w  w . j  av a  2  s  .c  o m*/
    return prefs.getInt(POINT_SAVED_INDEX, 0);
}

From source file:com.polyvi.xface.extension.camera.XCameraExt.java

private File createCaptureFile(int encodingType) {
    Context context = getContext();
    String picName = "";
    File photo = null;/* w ww . j a v  a2 s .  co m*/
    long time = Calendar.getInstance().getTimeInMillis();
    if (mEncodingType == JPEG) {
        picName = String.valueOf(time) + ".jpg";
    } else if (mEncodingType == PNG) {
        picName = String.valueOf(time) + ".png";
    } else {
        throw new IllegalArgumentException("Invalid Encoding Type: " + mEncodingType);
    }

    photo = context.getFileStreamPath(picName);
    if (!photo.exists()) {
        try {
            FileOutputStream outStream = context.openFileOutput(picName,
                    Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE);
            outStream.close();
            photo = context.getFileStreamPath(picName);
        } catch (FileNotFoundException e) {
            XLog.e(CLASS_NAME, "Create picture failed!");
        } catch (IOException e) {
            XLog.e(CLASS_NAME, "Close picture fileStream failed!");
        }
    }
    return photo;
}

From source file:com.thoughtmetric.tl.TLLib.java

private static TagNode TagNodeFromURLHelper(InputStream is, String fullTag, Handler handler, Context context,
        HtmlCleaner cleaner) throws IOException {
    SharedPreferences settings = context.getSharedPreferences(Settings.SETTINGS_FILE_NAME, 0);
    boolean disableSmartParsing = settings.getBoolean(Settings.DISABLE_SMART_PARSING, false);
    if (fullTag != null && !disableSmartParsing) {
        FileOutputStream fos = context.openFileOutput(TEMP_FILE_NAME, Context.MODE_WORLD_WRITEABLE);
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos));
        TagParser.extractTagToFile(fullTag, is, bw);
        bw.flush();/*from  ww w  .j  ava 2 s .c  o m*/
        bw.close();
        if (handler != null)
            handler.sendEmptyMessage(PROGRESS_PARSING);

        return cleaner.clean(context.openFileInput(TEMP_FILE_NAME));
    } else {
        if (handler != null)
            handler.sendEmptyMessage(PROGRESS_PARSING);
        return cleaner.clean(is);
    }
}

From source file:com.daiv.android.twitter.utils.NotificationUtils.java

public static int[] getUnreads(Context context) {
    SharedPreferences sharedPrefs = context.getSharedPreferences("com.daiv.android.twitter_world_preferences",
            Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE);
    int currentAccount = sharedPrefs.getInt("current_account", 1);

    HomeDataSource data = HomeDataSource.getInstance(context);
    int homeTweets = data.getUnreadCount(currentAccount);

    MentionsDataSource mentions = MentionsDataSource.getInstance(context);
    int mentionsTweets = mentions.getUnreadCount(currentAccount);

    int dmTweets = sharedPrefs.getInt("dm_unread_" + currentAccount, 0);

    return new int[] { homeTweets, mentionsTweets, dmTweets };
}

From source file:com.geoffreybuttercrumbs.arewethereyet.DrawerFragment.java

@Override
public void onClick(View v) {
    SharedPreferences prefs = getActivity().getSharedPreferences("AreWeThereYet", Context.MODE_WORLD_WRITEABLE);
    Intent intent = getActivity().getIntent();
    intent.setClass(getActivity(), ZonePicker.class);
    ZonePicker sfa = (ZonePicker) getActivity();
    switch (((View) v.getParent()).getId()) {
    case R.id.group_pinned:
        intent.putExtra(RADIUS, prefs.getInt(SAVED_RADIUS_KEY + v.findViewById(R.id.saveCB).getTag(), 2000));
        intent.putExtra(LOC, retrieveSaved((Integer) v.findViewById(R.id.saveCB).getTag()));
        getActivity().setResult(Activity.RESULT_OK, intent);
        sfa.setNewAlarmZone(intent.getExtras());
        sfa.showContent();/*from  w  w w .  j  av  a  2  s  .com*/
        break;
    case R.id.group_recent:
        intent.putExtra(RADIUS, prefs.getInt(POINT_RADIUS_KEY + v.findViewById(R.id.saveCB).getTag(), 2000));
        intent.putExtra(LOC, retrieveRecent((Integer) v.findViewById(R.id.saveCB).getTag()));
        getActivity().setResult(Activity.RESULT_OK, intent);
        sfa.setNewAlarmZone(intent.getExtras());
        sfa.showContent();
        break;
    }
}

From source file:org.mozilla.gecko.GeckoAppShell.java

public static boolean loadLibsSetup(String apkName) {
    // The package data lib directory isn't placed in ld.so's
    // search path, so we have to manually load libraries that
    // libxul will depend on.  Not ideal.
    GeckoApp geckoApp = GeckoApp.mAppContext;
    GeckoProfile profile = geckoApp.getProfile();
    profile.moveProfilesToAppInstallLocation();

    try {/*  w  w  w.ja v  a 2 s.c o m*/
        String[] dirs = GeckoApp.mAppContext.getPluginDirectories();
        StringBuffer pluginSearchPath = new StringBuffer();
        for (int i = 0; i < dirs.length; i++) {
            Log.i(LOGTAG, "dir: " + dirs[i]);
            pluginSearchPath.append(dirs[i]);
            pluginSearchPath.append(":");
        }
        GeckoAppShell.putenv("MOZ_PLUGIN_PATH=" + pluginSearchPath);
    } catch (Exception ex) {
        Log.i(LOGTAG, "exception getting plugin dirs", ex);
    }

    GeckoAppShell.putenv("HOME=" + profile.getFilesDir().getPath());
    GeckoAppShell.putenv("GRE_HOME=" + GeckoApp.sGREDir.getPath());
    Intent i = geckoApp.getIntent();
    String env = i.getStringExtra("env0");
    Log.i(LOGTAG, "env0: " + env);
    for (int c = 1; env != null; c++) {
        GeckoAppShell.putenv(env);
        env = i.getStringExtra("env" + c);
        Log.i(LOGTAG, "env" + c + ": " + env);
    }

    File f = geckoApp.getDir("tmp", Context.MODE_WORLD_READABLE | Context.MODE_WORLD_WRITEABLE);

    if (!f.exists())
        f.mkdirs();

    GeckoAppShell.putenv("TMPDIR=" + f.getPath());

    f = Environment.getDownloadCacheDirectory();
    GeckoAppShell.putenv("EXTERNAL_STORAGE=" + f.getPath());

    File cacheFile = getCacheDir();
    String linkerCache = System.getenv("MOZ_LINKER_CACHE");
    if (System.getenv("MOZ_LINKER_CACHE") == null) {
        GeckoAppShell.putenv("MOZ_LINKER_CACHE=" + cacheFile.getPath());
    }

    File pluginDataDir = GeckoApp.mAppContext.getDir("plugins", 0);
    GeckoAppShell.putenv("ANDROID_PLUGIN_DATADIR=" + pluginDataDir.getPath());

    // gingerbread introduces File.getUsableSpace(). We should use that.
    long freeSpace = getFreeSpace();
    try {
        File downloadDir = null;
        File updatesDir = null;
        if (Build.VERSION.SDK_INT >= 8) {
            downloadDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
            updatesDir = GeckoApp.mAppContext.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS);
        } else {
            updatesDir = downloadDir = new File(Environment.getExternalStorageDirectory().getPath(),
                    "download");
        }
        GeckoAppShell.putenv("DOWNLOADS_DIRECTORY=" + downloadDir.getPath());
        GeckoAppShell.putenv("UPDATES_DIRECTORY=" + updatesDir.getPath());
    } catch (Exception e) {
        Log.i(LOGTAG, "No download directory has been found: " + e);
    }

    putLocaleEnv();

    boolean extractLibs = GeckoApp.ACTION_DEBUG.equals(i.getAction());
    if (!extractLibs) {
        // remove any previously extracted libs
        File[] files = cacheFile.listFiles();
        if (files != null) {
            Iterator<File> cacheFiles = Arrays.asList(files).iterator();
            while (cacheFiles.hasNext()) {
                File libFile = cacheFiles.next();
                if (libFile.getName().endsWith(".so"))
                    libFile.delete();
            }
        }
    }
    return extractLibs;
}

From source file:com.geoffreybuttercrumbs.arewethereyet.DrawerFragment.java

private Location retrieveRecent(int index) {
    SharedPreferences prefs = getActivity().getSharedPreferences("AreWeThereYet", Context.MODE_WORLD_WRITEABLE);
    Location location = new Location("POINT_LOCATION");
    location.setLatitude(0);//from  ww w  . ja v a  2  s . c  o  m
    location.setLongitude(0);
    if (prefs.contains(POINT_LATITUDE_KEY + index)) {
        location.setLatitude(prefs.getFloat(POINT_LATITUDE_KEY + index, 0));
    }
    if (prefs.contains(POINT_LONGITUDE_KEY + index)) {
        location.setLongitude(prefs.getFloat(POINT_LONGITUDE_KEY + index, 0));
    }
    return location;
}