Example usage for android.content.pm ApplicationInfo FLAG_DEBUGGABLE

List of usage examples for android.content.pm ApplicationInfo FLAG_DEBUGGABLE

Introduction

In this page you can find the example usage for android.content.pm ApplicationInfo FLAG_DEBUGGABLE.

Prototype

int FLAG_DEBUGGABLE

To view the source code for android.content.pm ApplicationInfo FLAG_DEBUGGABLE.

Click Source Link

Document

Value for #flags : set to true if this application would like to allow debugging of its code, even when installed on a non-development system.

Usage

From source file:im.vector.activity.SettingsActivity.java

private void refreshGCMEntries() {
    GcmRegistrationManager gcmRegistrationManager = Matrix.getInstance(this).getSharedGcmRegistrationManager();

    Boolean debugMode = (0 != (getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE));

    final CheckBox gcmBox = (CheckBox) findViewById(R.id.checkbox_useGcm);
    gcmBox.setChecked(gcmRegistrationManager.useGCM() && gcmRegistrationManager.is3rdPartyServerRegistred());

    EditText editText = (EditText) findViewById(R.id.editText_gcm_pusher_url);
    editText.setText(gcmRegistrationManager.pusherUrl());

    editText = (EditText) findViewById(R.id.editText_gcm_pusher_profile_tag);
    editText.setText(gcmRegistrationManager.pusherFileTag());
}

From source file:com.sentaroh.android.SMBSync2.CommonUtilities.java

public boolean isDebuggable() {
    PackageManager manager = mContext.getPackageManager();
    ApplicationInfo appInfo = null;//  www.  j  av  a2s.  c  om
    try {
        appInfo = manager.getApplicationInfo(mContext.getPackageName(), 0);
    } catch (NameNotFoundException e) {
        return false;
    }
    if ((appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) == ApplicationInfo.FLAG_DEBUGGABLE)
        return true;
    return false;
}

From source file:biz.bokhorst.xprivacy.Util.java

public static boolean isDebuggable(Context context) {
    return ((context.getApplicationContext().getApplicationInfo().flags
            & ApplicationInfo.FLAG_DEBUGGABLE) != 0);
}

From source file:io.flutter.embedding.android.FlutterActivity.java

/**
 * Returns true if Flutter is running in "debug mode", and false otherwise.
 * <p>//w  ww  .ja va2s .c om
 * Debug mode allows Flutter to operate with hot reload and hot restart. Release mode does not.
 */
private boolean isDebuggable() {
    return (getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
}

From source file:com.alexdisler.inapppurchases.IabHelper.java

/**
 * Handles an activity result that's part of the purchase flow in in-app billing. If you
 * are calling {@link #launchPurchaseFlow}, then you must call this method from your
 * Activity's {@link android.app.Activity@onActivityResult} method. This method
 * MUST be called from the UI thread of the Activity.
 *
 * @param requestCode The requestCode as you received it.
 * @param resultCode The resultCode as you received it.
 * @param data The data (Intent) as you received it.
 * @return Returns true if the result was related to a purchase flow and was handled;
 *     false if the result was not related to a purchase, in which case you should
 *     handle it normally.//from  www . ja  va2s . c  om
 */
public boolean handleActivityResult(int requestCode, int resultCode, Intent data) {
    IabResult result;
    if (requestCode != mRequestCode)
        return false;

    checkNotDisposed();
    checkSetupDone("handleActivityResult");

    // end of async purchase operation that started on launchPurchaseFlow
    flagEndAsync();

    if (data == null) {
        logError("Null data in IAB activity result.");
        result = new IabResult(IABHELPER_BAD_RESPONSE, "Null data in IAB result");
        if (mPurchaseListener != null)
            mPurchaseListener.onIabPurchaseFinished(result, null);
        return true;
    }

    int responseCode = getResponseCodeFromIntent(data);
    String purchaseData = data.getStringExtra(RESPONSE_INAPP_PURCHASE_DATA);
    String dataSignature = data.getStringExtra(RESPONSE_INAPP_SIGNATURE);

    if (resultCode == Activity.RESULT_OK && responseCode == BILLING_RESPONSE_RESULT_OK) {
        logDebug("Successful resultcode from purchase activity.");
        logDebug("Purchase data: " + purchaseData);
        logDebug("Data signature: " + dataSignature);
        logDebug("Extras: " + data.getExtras());
        logDebug("Expected item type: " + mPurchasingItemType);

        if (purchaseData == null || dataSignature == null) {
            logError("BUG: either purchaseData or dataSignature is null.");
            logDebug("Extras: " + data.getExtras().toString());
            result = new IabResult(IABHELPER_UNKNOWN_ERROR, "IAB returned null purchaseData or dataSignature");
            if (mPurchaseListener != null)
                mPurchaseListener.onIabPurchaseFinished(result, null);
            return true;
        }

        Purchase purchase = null;
        try {
            purchase = new Purchase(mPurchasingItemType, purchaseData, dataSignature);
            String sku = purchase.getSku();
            // Only allow purchase verification to be skipped if we are debuggable
            boolean skipPurchaseVerification = (this.mSkipPurchaseVerification
                    && ((mContext.getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0));
            // Verify signature
            if (!skipPurchaseVerification) {
                if (!Security.verifyPurchase(mSignatureBase64, purchaseData, dataSignature)) {
                    logError("Purchase signature verification FAILED for sku " + sku);
                    result = new IabResult(IABHELPER_VERIFICATION_FAILED,
                            "Signature verification failed for sku " + sku);
                    if (mPurchaseListener != null)
                        mPurchaseListener.onIabPurchaseFinished(result, purchase);
                    return true;
                }
                logDebug("Purchase signature successfully verified.");
            }
        } catch (JSONException e) {
            logError("Failed to parse purchase data.");
            e.printStackTrace();
            result = new IabResult(IABHELPER_BAD_RESPONSE, "Failed to parse purchase data.");
            if (mPurchaseListener != null)
                mPurchaseListener.onIabPurchaseFinished(result, null);
            return true;
        }

        if (mPurchaseListener != null) {
            mPurchaseListener.onIabPurchaseFinished(new IabResult(BILLING_RESPONSE_RESULT_OK, "Success"),
                    purchase);
        }
    } else if (resultCode == Activity.RESULT_OK) {
        // result code was OK, but in-app billing response was not OK.
        logDebug("Result code was OK but in-app billing response was not OK: " + getResponseDesc(responseCode));
        if (mPurchaseListener != null) {
            result = new IabResult(responseCode, "Problem purchashing item.");
            mPurchaseListener.onIabPurchaseFinished(result, null);
        }
    } else if (resultCode == Activity.RESULT_CANCELED) {
        logDebug("Purchase canceled - Response: " + getResponseDesc(responseCode));
        result = new IabResult(IABHELPER_USER_CANCELLED, "User canceled.");
        if (mPurchaseListener != null)
            mPurchaseListener.onIabPurchaseFinished(result, null);
    } else {
        logError("Purchase failed. Result code: " + Integer.toString(resultCode) + ". Response: "
                + getResponseDesc(responseCode));
        result = new IabResult(IABHELPER_UNKNOWN_PURCHASE_RESPONSE, "Unknown purchase response.");
        if (mPurchaseListener != null)
            mPurchaseListener.onIabPurchaseFinished(result, null);
    }
    return true;
}

From source file:org.brandroid.openmanager.activities.OpenExplorer.java

public void onCreate(Bundle savedInstanceState) {
    Thread.setDefaultUncaughtExceptionHandler(new CustomExceptionHandler());

    if (getPreferences().getBoolean("global", "pref_fullscreen", false)) {
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        IS_FULL_SCREEN = true;/*from w w w .j a  va  2 s  .c om*/
    } //else getWindow().addFlags(WindowManager.LayoutParams.FLAG
    else {
        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
        IS_FULL_SCREEN = false;
    }

    IS_KEYBOARD_AVAILABLE = getContext().getResources()
            .getConfiguration().keyboard == Configuration.KEYBOARD_QWERTY;

    loadPreferences();

    if (getPreferences().getBoolean("global", "pref_hardware_accel", true) && !BEFORE_HONEYCOMB)
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
                WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);

    //mActionBarHelper = ActionBarHelper.createInstance(this);
    //mActionBarHelper.onCreate(savedInstanceState);
    if (BEFORE_HONEYCOMB) {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        USE_ACTION_BAR = false;
        //} else if(isGTV()) {
        //   USE_ACTION_BAR = false;
        //   mBar = (LeftNavBarService.instance()).getLeftNavBar(this);
    } else if (!BEFORE_HONEYCOMB) {
        requestWindowFeature(Window.FEATURE_ACTION_BAR);
        USE_ACTION_BAR = true;
        mBar = getActionBar();
    }
    if (mBar != null) {
        if (Build.VERSION.SDK_INT >= 14)
            mBar.setHomeButtonEnabled(true);
        mBar.setDisplayUseLogoEnabled(true);
        try {
            mBar.setCustomView(R.layout.title_bar);
            mBar.setDisplayShowCustomEnabled(true);
            mBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
            //ViewGroup cv = (ViewGroup)ab.getCustomView();
            //if(cv.findViewById(R.id.title_paste) != null)
            //   cv.removeView(cv.findViewById(R.id.title_paste));
            //ab.getCustomView().findViewById(R.id.title_icon).setVisibility(View.GONE);
        } catch (InflateException e) {
            Logger.LogWarning("Couldn't set up ActionBar custom view", e);
        }
    } else
        USE_ACTION_BAR = false;

    OpenFile.setTempFileRoot(new OpenFile(getFilesDir()).getChild("temp"));
    setupLoggingDb();
    handleExceptionHandler();
    getMimeTypes();
    setupFilesDb();

    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_fragments);
    getWindow().setBackgroundDrawableResource(R.drawable.background_holo_dark);

    try {
        upgradeViewSettings();
    } catch (Exception e) {
    }
    //try {
    showWarnings();
    //} catch(Exception e) { }

    mEvHandler.setUpdateListener(this);

    getClipboard().setClipboardUpdateListener(this);

    try {
        /*
        Signature[] sigs = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_SIGNATURES).signatures;
        for(Signature sig : sigs)
           if(sig.toCharsString().indexOf("4465627567") > -1) // check for "Debug" in signature
              IS_DEBUG_BUILD = true;
        */
        if (IS_DEBUG_BUILD)
            IS_DEBUG_BUILD = (getPackageManager().getActivityInfo(getComponentName(),
                    PackageManager.GET_META_DATA).applicationInfo.flags
                    & ApplicationInfo.FLAG_DEBUGGABLE) == ApplicationInfo.FLAG_DEBUGGABLE;
        if (isBlackBerry())
            IS_DEBUG_BUILD = false;
    } catch (NameNotFoundException e1) {
    }

    handleNetworking();
    refreshCursors();

    checkWelcome();

    checkRoot();

    if (!BEFORE_HONEYCOMB) {
        boolean show_underline = true;
        if (Build.VERSION.SDK_INT < 14)
            show_underline = isGTV();
        else if (getResources().getBoolean(R.bool.large)) // ICS+ tablets
            show_underline = false;
        if (Build.VERSION.SDK_INT > 13 && !getResources().getBoolean(R.bool.large))
            show_underline = true;

        View tu = findViewById(R.id.title_underline);
        if (tu != null && !show_underline) {
            getActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.actionbar_shadow));
            tu.setVisibility(View.GONE);
        }

        //if(USE_ACTION_BAR)
        //   setViewVisibility(false, false, R.id.title_bar, R.id.title_underline, R.id.title_underline_2);
    }
    if (BEFORE_HONEYCOMB || !USE_ACTION_BAR)
        ViewUtils.inflateView(this, R.id.title_stub);
    if (BEFORE_HONEYCOMB)
        ViewUtils.inflateView(this, R.id.base_stub);
    setViewVisibility(false, false, R.id.title_paste, R.id.title_ops, R.id.title_log);
    setOnClicks(R.id.title_ops, //R.id.menu_global_ops_icon, R.id.menu_global_ops_text,
            R.id.title_log, R.id.title_icon, R.id.menu_more, R.id.title_paste_icon
    //,R.id.title_sort, R.id.title_view, R.id.title_up
    );
    checkTitleSeparator();
    IconContextMenu.clearInstances();

    if (findViewById(R.id.list_frag) == null)
        mSinglePane = true;
    else if (findViewById(R.id.list_frag).getVisibility() == View.GONE)
        mSinglePane = true;

    Logger.LogDebug("Looking for path");
    OpenPath path = mLastPath;
    if (savedInstanceState == null || path == null) {
        String start = getPreferences().getString("global", "pref_start", "External");

        if (savedInstanceState != null && savedInstanceState.containsKey("last")
                && !savedInstanceState.getString("last").equals(""))
            start = savedInstanceState.getString("last");

        path = FileManager.getOpenCache(start, this);
    }

    if (path == null)
        path = OpenFile.getExternalMemoryDrive(true);

    if (FileManager.checkForNoMedia(path))
        showToast(R.string.s_error_no_media, Toast.LENGTH_LONG);

    mLastPath = path;

    boolean bAddToStack = true;

    if (findViewById(R.id.content_pager_frame_stub) != null)
        ((ViewStub) findViewById(R.id.content_pager_frame_stub)).inflate();

    Logger.LogDebug("Pager inflated");

    if (fragmentManager == null) {
        fragmentManager = getSupportFragmentManager();
        fragmentManager.addOnBackStackChangedListener(this);
    }

    mLogFragment = new LogViewerFragment();

    FragmentTransaction ft = fragmentManager.beginTransaction();

    Logger.LogDebug("Creating with " + path.getPath());
    if (path instanceof OpenFile)
        new PeekAtGrandKidsTask().execute((OpenFile) path);

    initPager();
    if (handleIntent(getIntent())) {
        path = mLastPath = null;
        bAddToStack = false;
    }

    if (mViewPager != null && mViewPagerAdapter != null && path != null) {
        //mViewPagerAdapter.add(mContentFragment);
        mLastPath = null;
        changePath(path, bAddToStack, true);
        setCurrentItem(mViewPagerAdapter.getCount() - 1, false);
        restoreOpenedEditors();
    } else
        Logger.LogWarning("Nothing to show?!");

    ft.commit();

    invalidateOptionsMenu();
    initBookmarkDropdown();

    handleMediaReceiver();

    if (!getPreferences().getBoolean("global", "pref_splash", false))
        showSplashIntent(this, getPreferences().getString("global", "pref_start", "Internal"));
}

From source file:com.paywith.ibeacon.service.IBeaconService.java

@TargetApi(18)
private void finishScanCycle() {
    if (android.os.Build.VERSION.SDK_INT < 18) {
        Log.w(TAG, "Not supported prior to API 18.");
        return;//  w ww.j a  v  a 2  s.  co m
    }
    if (IBeaconManager.debug)
        Log.d(TAG, "Done with scan cycle");
    processExpiredMonitors();
    if (scanning == true) {
        processRangeData();
        // If we want to use simulated scanning data, do it here.  This is used for testing in an emulator
        if (simulatedScanData != null) {
            // if simulatedScanData is provided, it will be seen every scan cycle.  *in addition* to anything actually seen in the air
            // it will not be used if we are not in debug mode
            Log.w(TAG,
                    "Simulated scan data is deprecated and will be removed in a future release. Please use the new BeaconSimulator interface instead.");

            if (0 != (getApplicationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE)) {
                for (IBeacon iBeacon : simulatedScanData) {
                    processIBeaconFromScan(iBeacon);
                }
            } else {
                Log.w(TAG,
                        "Simulated scan data provided, but ignored because we are not running in debug mode.  Please remove simulated scan data for production.");
            }
        }

        if (getBluetoothAdapter() != null) {
            if (getBluetoothAdapter().isEnabled()) {
                getBluetoothAdapter().stopLeScan((BluetoothAdapter.LeScanCallback) getLeScanCallback());
                lastScanEndTime = new Date().getTime();
            } else {
                Log.w(TAG, "Bluetooth is disabled.  Cannot scan for iBeacons.");
            }
        }

        if (!anyRangingOrMonitoringRegionsActive()) {
            if (IBeaconManager.debug)
                Log.d(TAG, "Not starting scan because no monitoring or ranging regions are defined.");
            scanCyclerStarted = false;
        } else {
            if (IBeaconManager.debug)
                Log.d(TAG, "Restarting scan.  Unique beacons seen last cycle: " + trackedBeacons.size()
                        + " Total iBeacon advertisement packets seen: " + trackedBeaconsPacketCount);

            scanningPaused = true;
            nextScanStartTime = (new Date().getTime() + betweenScanPeriod);
            if (scanningEnabled) {
                scanLeDevice(true);
            } else {
                if (IBeaconManager.debug)
                    Log.d(TAG, "Scanning disabled.  No ranging or monitoring regions are active.");
                scanCyclerStarted = false;
            }
        }
    }
}

From source file:es.javocsoft.android.lib.toolbox.ToolBox.java

/**
 * This method reads the info form the App. Manifest file.
 * /*from  w  w w. ja v  a2  s  .  c  o  m*/
 * @return
 */
public static boolean application_isAppInDebugMode(Context context) {
    boolean res = false;

    try {
        PackageInfo info = context.getPackageManager().getPackageInfo(context.getApplicationInfo().packageName,
                0);

        int flags = info.applicationInfo.flags;
        if ((flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
            // development mode
            res = true;
        } else {
            // release mode
        }
    } catch (Exception e) {
        if (LOG_ENABLE)
            Log.e("IS_DEBUG_MODE:ERROR", e.getMessage(), e);
    }

    return res;
}

From source file:com.apptentive.android.sdk.Apptentive.java

private static void init(Activity activity) {

    ///*from   w w w  .  j av a2  s  .c  o  m*/
    // First, initialize data relies on synchronous reads from local resources.
    //

    final Context appContext = activity.getApplicationContext();

    if (!GlobalInfo.initialized) {
        SharedPreferences prefs = appContext.getSharedPreferences(Constants.PREF_NAME, Context.MODE_PRIVATE);

        // First, Get the api key, and figure out if app is debuggable.
        GlobalInfo.isAppDebuggable = false;
        String apiKey = null;
        boolean apptentiveDebug = false;
        String logLevelOverride = null;
        try {
            ApplicationInfo ai = appContext.getPackageManager().getApplicationInfo(appContext.getPackageName(),
                    PackageManager.GET_META_DATA);
            Bundle metaData = ai.metaData;
            if (metaData != null) {
                apiKey = metaData.getString(Constants.MANIFEST_KEY_APPTENTIVE_API_KEY);
                logLevelOverride = metaData.getString(Constants.MANIFEST_KEY_APPTENTIVE_LOG_LEVEL);
                apptentiveDebug = metaData.getBoolean(Constants.MANIFEST_KEY_APPTENTIVE_DEBUG);
                ApptentiveClient.useStagingServer = metaData
                        .getBoolean(Constants.MANIFEST_KEY_USE_STAGING_SERVER);
            }
            if (apptentiveDebug) {
                Log.i("Apptentive debug logging set to VERBOSE.");
                ApptentiveInternal.setMinimumLogLevel(Log.Level.VERBOSE);
            } else if (logLevelOverride != null) {
                Log.i("Overriding log level: %s", logLevelOverride);
                ApptentiveInternal.setMinimumLogLevel(Log.Level.parse(logLevelOverride));
            } else {
                GlobalInfo.isAppDebuggable = (ai.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
                if (GlobalInfo.isAppDebuggable) {
                    ApptentiveInternal.setMinimumLogLevel(Log.Level.VERBOSE);
                }
            }
        } catch (Exception e) {
            Log.e("Unexpected error while reading application info.", e);
        }

        Log.i("Debug mode enabled? %b", GlobalInfo.isAppDebuggable);

        // If we are in debug mode, but no api key is found, throw an exception. Otherwise, just assert log. We don't want to crash a production app.
        String errorString = "No Apptentive api key specified. Please make sure you have specified your api key in your AndroidManifest.xml";
        if ((Util.isEmpty(apiKey))) {
            if (GlobalInfo.isAppDebuggable) {
                AlertDialog alertDialog = new AlertDialog.Builder(activity).setTitle("Error")
                        .setMessage(errorString).setPositiveButton("OK", null).create();
                alertDialog.setCanceledOnTouchOutside(false);
                alertDialog.show();
            }
            Log.e(errorString);
        }
        GlobalInfo.apiKey = apiKey;

        Log.i("API Key: %s", GlobalInfo.apiKey);

        // Grab app info we need to access later on.
        GlobalInfo.appPackage = appContext.getPackageName();
        GlobalInfo.androidId = Settings.Secure.getString(appContext.getContentResolver(),
                android.provider.Settings.Secure.ANDROID_ID);

        // Check the host app version, and notify modules if it's changed.
        try {
            PackageManager packageManager = appContext.getPackageManager();
            PackageInfo packageInfo = packageManager.getPackageInfo(appContext.getPackageName(), 0);

            Integer currentVersionCode = packageInfo.versionCode;
            String currentVersionName = packageInfo.versionName;
            VersionHistoryStore.VersionHistoryEntry lastVersionEntrySeen = VersionHistoryStore
                    .getLastVersionSeen(appContext);
            if (lastVersionEntrySeen == null) {
                onVersionChanged(appContext, null, currentVersionCode, null, currentVersionName);
            } else {
                if (!currentVersionCode.equals(lastVersionEntrySeen.versionCode)
                        || !currentVersionName.equals(lastVersionEntrySeen.versionName)) {
                    onVersionChanged(appContext, lastVersionEntrySeen.versionCode, currentVersionCode,
                            lastVersionEntrySeen.versionName, currentVersionName);
                }
            }

            GlobalInfo.appDisplayName = packageManager
                    .getApplicationLabel(packageManager.getApplicationInfo(packageInfo.packageName, 0))
                    .toString();
        } catch (PackageManager.NameNotFoundException e) {
            // Nothing we can do then.
            GlobalInfo.appDisplayName = "this app";
        }

        // Grab the conversation token from shared preferences.
        if (prefs.contains(Constants.PREF_KEY_CONVERSATION_TOKEN)
                && prefs.contains(Constants.PREF_KEY_PERSON_ID)) {
            GlobalInfo.conversationToken = prefs.getString(Constants.PREF_KEY_CONVERSATION_TOKEN, null);
            GlobalInfo.personId = prefs.getString(Constants.PREF_KEY_PERSON_ID, null);
        }

        GlobalInfo.initialized = true;
        Log.v("Done initializing...");
    } else {
        Log.v("Already initialized...");
    }

    // Initialize the Conversation Token, or fetch if needed. Fetch config it the token is available.
    if (GlobalInfo.conversationToken == null || GlobalInfo.personId == null) {
        asyncFetchConversationToken(appContext.getApplicationContext());
    } else {
        asyncFetchAppConfiguration(appContext.getApplicationContext());
        InteractionManager.asyncFetchAndStoreInteractions(appContext.getApplicationContext());
    }

    // TODO: Do this on a dedicated thread if it takes too long. Some devices are slow to read device data.
    syncDevice(appContext);
    syncSdk(appContext);
    syncPerson(appContext);

    Log.d("Default Locale: %s", Locale.getDefault().toString());
    SharedPreferences prefs = appContext.getSharedPreferences(Constants.PREF_NAME, Context.MODE_PRIVATE);
    Log.d("Conversation id: %s", prefs.getString(Constants.PREF_KEY_CONVERSATION_ID, "null"));
}

From source file:com.alexdisler.inapppurchases.IabHelper.java

int queryPurchases(Inventory inv, String itemType) throws JSONException, RemoteException {
    // Query purchases
    logDebug("Querying owned items, item type: " + itemType);
    logDebug("Package name: " + mContext.getPackageName());
    boolean verificationFailed = false;
    // Only allow purchase verification to be skipped if we are debuggable
    boolean skipPurchaseVerification = (this.mSkipPurchaseVerification
            && ((mContext.getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0));
    String continueToken = null;/*from   w  w w .j a  v  a2  s .c o m*/

    do {
        logDebug("Calling getPurchases with continuation token: " + continueToken);
        Bundle ownedItems = mService.getPurchases(3, mContext.getPackageName(), itemType, continueToken);

        int response = getResponseCodeFromBundle(ownedItems);
        logDebug("Owned items response: " + String.valueOf(response));
        if (response != BILLING_RESPONSE_RESULT_OK) {
            logDebug("getPurchases() failed: " + getResponseDesc(response));
            return response;
        }
        if (!ownedItems.containsKey(RESPONSE_INAPP_ITEM_LIST)
                || !ownedItems.containsKey(RESPONSE_INAPP_PURCHASE_DATA_LIST)
                || !ownedItems.containsKey(RESPONSE_INAPP_SIGNATURE_LIST)) {
            logError("Bundle returned from getPurchases() doesn't contain required fields.");
            return IABHELPER_BAD_RESPONSE;
        }

        ArrayList<String> ownedSkus = ownedItems.getStringArrayList(RESPONSE_INAPP_ITEM_LIST);
        ArrayList<String> purchaseDataList = ownedItems.getStringArrayList(RESPONSE_INAPP_PURCHASE_DATA_LIST);
        ArrayList<String> signatureList = ownedItems.getStringArrayList(RESPONSE_INAPP_SIGNATURE_LIST);

        for (int i = 0; i < purchaseDataList.size(); ++i) {
            String purchaseData = purchaseDataList.get(i);
            String signature = signatureList.get(i);
            String sku = ownedSkus.get(i);
            if (skipPurchaseVerification
                    || Security.verifyPurchase(mSignatureBase64, purchaseData, signature)) {
                logDebug("Sku is owned: " + sku);
                Purchase purchase = new Purchase(itemType, purchaseData, signature);

                if (TextUtils.isEmpty(purchase.getToken())) {
                    logWarn("BUG: empty/null token!");
                    logDebug("Purchase data: " + purchaseData);
                }

                // Record ownership and token
                inv.addPurchase(purchase);
            } else {
                logWarn("Purchase signature verification **FAILED**. Not adding item.");
                logDebug("   Purchase data: " + purchaseData);
                logDebug("   Signature: " + signature);
                verificationFailed = true;
            }
        }

        continueToken = ownedItems.getString(INAPP_CONTINUATION_TOKEN);
        logDebug("Continuation token: " + continueToken);
    } while (!TextUtils.isEmpty(continueToken));

    return verificationFailed ? IABHELPER_VERIFICATION_FAILED : BILLING_RESPONSE_RESULT_OK;
}