io.grpc.internal.DnsNameResolverProvider#com.google.android.gms.security.ProviderInstaller源码实例Demo

下面列出了io.grpc.internal.DnsNameResolverProvider#com.google.android.gms.security.ProviderInstaller 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: mollyim-android   文件: AccountManagerFactory.java
public static @NonNull SignalServiceAccountManager createAuthenticated(@NonNull Context context,
                                                                       @NonNull UUID uuid,
                                                                       @NonNull String number,
                                                                       @NonNull String password)
{
  if (new SignalServiceNetworkAccess(context).isCensored(number)) {
    SignalExecutors.BOUNDED.execute(() -> {
      try {
        ProviderInstaller.installIfNeeded(context);
      } catch (Throwable t) {
        Log.w(TAG, t);
      }
    });
  }

  return new SignalServiceAccountManager(new SignalServiceNetworkAccess(context).getConfiguration(number),
                                         uuid, number, password, BuildConfig.SIGNAL_AGENT);
}
 
源代码2 项目: mollyim-android   文件: AccountManagerFactory.java
/**
 * Should only be used during registration when you haven't yet been assigned a UUID.
 */
public static @NonNull SignalServiceAccountManager createUnauthenticated(@NonNull Context context,
                                                                         @NonNull String number,
                                                                         @NonNull String password)
{
  if (new SignalServiceNetworkAccess(context).isCensored(number)) {
    SignalExecutors.BOUNDED.execute(() -> {
      try {
        ProviderInstaller.installIfNeeded(context);
      } catch (Throwable t) {
        Log.w(TAG, t);
      }
    });
  }

  return new SignalServiceAccountManager(new SignalServiceNetworkAccess(context).getConfiguration(number),
                                         null, number, password, BuildConfig.SIGNAL_AGENT);
}
 
源代码3 项目: mollyim-android   文件: ApplicationContext.java
@SuppressLint("StaticFieldLeak")
private void initializeCircumvention() {
  AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() {
    @Override
    protected Void doInBackground(Void... params) {
      if (new SignalServiceNetworkAccess(ApplicationContext.this).isCensored(ApplicationContext.this)) {
        try {
          ProviderInstaller.installIfNeeded(ApplicationContext.this);
        } catch (Throwable t) {
          Log.w(TAG, t);
        }
      }
      return null;
    }
  };

  task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
 
源代码4 项目: grpc-nebula-java   文件: TesterActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_tester);
  buttons = new LinkedList<>();
  buttons.add((Button) findViewById(R.id.empty_unary_button));
  buttons.add((Button) findViewById(R.id.large_unary_button));
  buttons.add((Button) findViewById(R.id.client_streaming_button));
  buttons.add((Button) findViewById(R.id.server_streaming_button));
  buttons.add((Button) findViewById(R.id.ping_pong_button));

  hostEdit = (EditText) findViewById(R.id.host_edit_text);
  portEdit = (EditText) findViewById(R.id.port_edit_text);
  resultText = (TextView) findViewById(R.id.grpc_response_text);
  getCheckBox = (CheckBox) findViewById(R.id.get_checkbox);
  testCertCheckBox = (CheckBox) findViewById(R.id.test_cert_checkbox);

  ProviderInstaller.installIfNeededAsync(this, this);
  // Disable buttons until the security provider installing finishes.
  enableButtons(false);
}
 
源代码5 项目: developerWorks   文件: MainActivity.java
/**
 * Returns the SSLSocketFactory to use to connect to the MQTT server over ssl://
 * @param context The ApplicationContext to use
 * @return SSLSocketFactory
 */
private SSLSocketFactory getSSLSocketFactory(Context context) {
    SSLSocketFactory factory = null;
    try {
        ProviderInstaller.installIfNeeded(context);

        SSLContext sslContext;
        KeyStore ks = KeyStore.getInstance("bks");
        ks.load(context.getResources().openRawResource(R.raw.iot), "password".toCharArray());
        TrustManagerFactory tmf = TrustManagerFactory.getInstance("X509");
        tmf.init(ks);
        TrustManager[] tm = tmf.getTrustManagers();
        sslContext = SSLContext.getInstance("TLSv1.2");
        sslContext.init(null, tm, null);
        factory = sslContext.getSocketFactory();
    } catch (Exception e) {
        String notificationMessage = "Exception thrown trying to get SSLSocketFactory: ";
        Log.e(TAG, notificationMessage, e);
        // Store this in the Notification deque
        pushNotification(notificationMessage);
    }
    return factory;
}
 
源代码6 项目: grpc-java   文件: TesterActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_tester);
  buttons = new ArrayList<>();
  buttons.add((Button) findViewById(R.id.empty_unary_button));
  buttons.add((Button) findViewById(R.id.large_unary_button));
  buttons.add((Button) findViewById(R.id.client_streaming_button));
  buttons.add((Button) findViewById(R.id.server_streaming_button));
  buttons.add((Button) findViewById(R.id.ping_pong_button));

  hostEdit = (EditText) findViewById(R.id.host_edit_text);
  portEdit = (EditText) findViewById(R.id.port_edit_text);
  resultText = (TextView) findViewById(R.id.grpc_response_text);
  testCertCheckBox = (CheckBox) findViewById(R.id.test_cert_checkbox);

  ProviderInstaller.installIfNeededAsync(this, this);
  // Disable buttons until the security provider installing finishes.
  enableButtons(false);
}
 
源代码7 项目: firebase-android-sdk   文件: GrpcCallProvider.java
/** Sets up the SSL provider and configures the gRPC channel. */
private ManagedChannel initChannel(Context context, DatabaseInfo databaseInfo) {
  try {
    // We need to upgrade the Security Provider before any network channels are initialized.
    // `OkHttp` maintains a list of supported providers that is initialized when the JVM first
    // resolves the static dependencies of ManagedChannel.
    ProviderInstaller.installIfNeeded(context);
  } catch (GooglePlayServicesNotAvailableException /* Thrown by ProviderInstaller */
      | GooglePlayServicesRepairableException /* Thrown by ProviderInstaller */
      | IllegalStateException e /* Thrown by Robolectric */) {
    // Mark the SSL initialization as done, even though we may be using outdated SSL
    // ciphers. gRPC-Java recommends obtaining updated ciphers from GMSCore, but we allow
    // the device to fall back to other SSL ciphers if GMSCore is not available.
    Logger.warn(LOG_TAG, "Failed to update ssl context: %s", e);
  }

  ManagedChannelBuilder<?> channelBuilder;
  if (overrideChannelBuilderSupplier != null) {
    channelBuilder = overrideChannelBuilderSupplier.get();
  } else {
    channelBuilder = ManagedChannelBuilder.forTarget(databaseInfo.getHost());
    if (!databaseInfo.isSslEnabled()) {
      // Note that the boolean flag does *NOT* switch the wire format from Protobuf to Plaintext.
      // It merely turns off SSL encryption.
      channelBuilder.usePlaintext();
    }
  }

  // Ensure gRPC recovers from a dead connection. (Not typically necessary, as the OS will
  // usually notify gRPC when a connection dies. But not always. This acts as a failsafe.)
  channelBuilder.keepAliveTime(30, TimeUnit.SECONDS);

  // Wrap the ManagedChannelBuilder in an AndroidChannelBuilder. This allows the channel to
  // respond more gracefully to network change events (such as switching from cell to wifi).
  AndroidChannelBuilder androidChannelBuilder =
      AndroidChannelBuilder.usingBuilder(channelBuilder).context(context);

  return androidChannelBuilder.build();
}
 
源代码8 项目: firebase-android-sdk   文件: FirebaseFunctions.java
/**
 * Runs ProviderInstaller.installIfNeededAsync once per application instance.
 *
 * @param context The application context.
 */
private static void maybeInstallProviders(Context context) {
  // Make sure this only runs once.
  synchronized (providerInstalled) {
    if (providerInstallStarted) {
      return;
    }
    providerInstallStarted = true;
  }

  // Package installIfNeededAsync into a Runnable so it can be run on the main thread.
  // installIfNeededAsync checks to make sure it is on the main thread, and throws otherwise.
  Runnable runnable =
      () ->
          ProviderInstaller.installIfNeededAsync(
              context,
              new ProviderInstallListener() {
                @Override
                public void onProviderInstalled() {
                  providerInstalled.setResult(null);
                }

                @Override
                public void onProviderInstallFailed(int i, android.content.Intent intent) {
                  Log.d("FirebaseFunctions", "Failed to update ssl context");
                  providerInstalled.setResult(null);
                }
              });

  Handler handler = new Handler(context.getMainLooper());
  handler.post(runnable);
}
 
源代码9 项目: APDE   文件: APDE.java
/**
 * Disable SSL3 to force TLS. Fix for Android 4.4 and below.
 *
 * https://stackoverflow.com/questions/29916962/javax-net-ssl-sslhandshakeexception-javax-net-ssl-sslprotocolexception-ssl-han
 */
public void disableSsl3() {
	try {
		ProviderInstaller.installIfNeeded(this);
	} catch (GooglePlayServicesNotAvailableException | GooglePlayServicesRepairableException e) {
		// Too bad
		System.err.println("Failed to disable SSL3");
	}
}
 
源代码10 项目: Saiy-PS   文件: MotionRecognition.java
/**
 * Prepare the Activity Recognition API for use.
 *
 * @param ctx the application context
 */
public void prepare(@NonNull final Context ctx) {

    final GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance();
    final int connectionResult = apiAvailability.isGooglePlayServicesAvailable(ctx);

    switch (connectionResult) {

        case ConnectionResult.SUCCESS:

            activityClient = new GoogleApiClient.Builder(ctx).addConnectionCallbacks(this)
                    .addOnConnectionFailedListener(this).addApi(ActivityRecognition.API).build();

            pendingIntent = PendingIntent.getService(ctx, MotionIntentService.REQUEST_CODE,
                    new Intent(ctx, MotionIntentService.class),
                    PendingIntent.FLAG_UPDATE_CURRENT);

            try {

                ProviderInstaller.installIfNeededAsync(ctx, new ProviderInstaller.ProviderInstallListener() {
                    @Override
                    public void onProviderInstalled() {
                        if (DEBUG) {
                            MyLog.i(CLS_NAME, "prepare: play services onProviderInstalled");
                        }
                    }

                    @Override
                    public void onProviderInstallFailed(final int errorCode, final Intent intent) {
                        if (DEBUG) {
                            MyLog.w(CLS_NAME, "prepare: play services onProviderInstallFailed");
                        }

                        if (apiAvailability.isUserResolvableError(errorCode)) {
                            if (DEBUG) {
                                MyLog.w(CLS_NAME, "prepare: play services onProviderInstallFailed");
                            }

                            apiAvailability.showErrorNotification(ctx, errorCode);

                        } else {
                            // TODO - unrecoverable
                        }
                    }
                });
            } catch (final Exception e) {
                if (DEBUG) {
                    MyLog.w(CLS_NAME, "prepare: play services unavailable");
                    e.printStackTrace();
                }
            }

            break;

        default:
            if (DEBUG) {
                MyLog.w(CLS_NAME, "prepare: play services unavailable");
            }
            apiAvailability.showErrorNotification(ctx, connectionResult);
            break;
    }
}
 
源代码11 项目: Hentoid   文件: HentoidApp.java
@Override
public void onCreate() {
    super.onCreate();
    instance = this;

    Fabric.with(this, new Crashlytics());

    // Fix the SSLHandshake error with okhttp on Android 4.1-4.4 when server only supports TLS1.2
    // see https://github.com/square/okhttp/issues/2372 for more information
    try {
        ProviderInstaller.installIfNeeded(getApplicationContext());
    } catch (Exception e) {
        Timber.e(e, "Google Play ProviderInstaller exception");
    }

    // Init datetime
    AndroidThreeTen.init(this);

    // Timber
    if (BuildConfig.DEBUG) Timber.plant(new Timber.DebugTree());
    Timber.plant(new CrashlyticsTree());

    // Prefs
    Preferences.init(this);
    Preferences.performHousekeeping();

    // Image viewer
    // Needs ARGB_8888 to be able to resize images using RenderScript
    // (defaults to Bitmap.Config.RGB_565 if not set)
    CustomSubsamplingScaleImageView.setPreferredBitmapConfig(Bitmap.Config.ARGB_8888);

    // Init version number on first run
    if (0 == Preferences.getLastKnownAppVersionCode())
        Preferences.setLastKnownAppVersionCode(BuildConfig.VERSION_CODE);

    // Firebase
    boolean isAnalyticsEnabled = Preferences.isAnalyticsEnabled();
    FirebaseAnalytics.getInstance(this).setAnalyticsCollectionEnabled(isAnalyticsEnabled);

    // DB housekeeping
    performDatabaseHousekeeping();

    // Init notification channels
    UpdateNotificationChannel.init(this);
    DownloadNotificationChannel.init(this);
    MaintenanceNotificationChannel.init(this);

    // Clears all previous notifications
    NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    if (manager != null) manager.cancelAll();

    // Run app update checks
    if (Preferences.isAutomaticUpdateEnabled()) {
        Intent intent = UpdateCheckService.makeIntent(this, false);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            startForegroundService(intent);
        } else {
            startService(intent);
        }
    }

    // Build Android shortcuts
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
        ShortcutHelper.buildShortcuts(this);
    }

    // Send stats to Firebase
    FirebaseAnalytics.getInstance(this).setUserProperty("color_theme", Integer.toString(Preferences.getColorTheme()));
    FirebaseAnalytics.getInstance(this).setUserProperty("endless", Boolean.toString(Preferences.getEndlessScroll()));

    // Plug the lifecycle listener to handle locking
    ProcessLifecycleOwner.get().getLifecycle().addObserver(new LifeCycleListener());

    // Set RxJava's default error handler for unprocessed network and IO errors
    RxJavaPlugins.setErrorHandler(e -> {
        if (e instanceof UndeliverableException) {
            e = e.getCause();
        }
        if (e instanceof IOException) {
            // fine, irrelevant network problem or API that throws on cancellation
            return;
        }
        if (e instanceof InterruptedException) {
            // fine, some blocking code was interrupted by a dispose call
            return;
        }
        Timber.w(e, "Undeliverable exception received, not sure what to do");
    });
}
 
源代码12 项目: Popeens-DSub   文件: GoogleCompat.java
public static void installProvider(Context context) throws Exception{
    ProviderInstaller.installIfNeeded(context);
}
 
源代码13 项目: KernelAdiutor   文件: MainActivity.java
/**
 * Determinate what sections are supported
 */
private void collectData() {
    MainActivity activity = mRefActivity.get();
    if (activity == null) return;

    Battery.getInstance(activity);
    CPUBoost.getInstance();

    // Assign core ctl min cpu
    CPUFreq.getInstance(activity);

    Device.CPUInfo.getInstance();
    Device.Input.getInstance();
    Device.MemInfo.getInstance();
    Device.ROMInfo.getInstance();
    Device.TrustZone.getInstance();
    GPU.supported();
    Hotplug.supported();
    IO.getInstance();
    KSM.getInstance();
    MSMPerformance.getInstance();
    QcomBcl.supported();
    Screen.supported();
    Sound.getInstance();
    Temperature.getInstance(activity);
    Thermal.supported();
    Tile.publishProfileTile(new Profiles(activity).getAllProfiles(), activity);
    Vibration.getInstance();
    Voltage.getInstance();
    Wake.supported();

    try {
        ProviderInstaller.installIfNeeded(activity);
    } catch (GooglePlayServicesNotAvailableException
            | GooglePlayServicesRepairableException e) {
        e.printStackTrace();
    }

    if (!BuildConfig.DEBUG) {
        // Send SoC type to analytics to collect stats
        Answers.getInstance().logCustom(new CustomEvent("SoC")
                .putCustomAttribute("type", Device.getBoard()));
    }

    Log.crashlyticsI(TAG, "Build Display ID: "
            + Device.getBuildDisplayId());
    Log.crashlyticsI(TAG, "ROM: "
            + Device.ROMInfo.getInstance().getVersion());
    Log.crashlyticsI(TAG, "Kernel version: "
            + Device.getKernelVersion(true));
    Log.crashlyticsI(TAG, "Board: " +
            Device.getBoard());
}