| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package org.chromium.chromoting.help; |
| 6 |
| 7 import android.app.Activity; |
| 8 import android.content.ComponentName; |
| 9 import android.content.Context; |
| 10 import android.content.Intent; |
| 11 import android.content.ServiceConnection; |
| 12 import android.graphics.Bitmap; |
| 13 import android.os.Binder; |
| 14 import android.os.IBinder; |
| 15 import android.os.Parcel; |
| 16 import android.os.RemoteException; |
| 17 import android.view.View; |
| 18 |
| 19 import org.chromium.base.Log; |
| 20 import org.chromium.ui.UiUtils; |
| 21 |
| 22 /** |
| 23 * This is a helper class for sending feedback. |
| 24 */ |
| 25 public class FeedbackSender { |
| 26 private static final String TAG = "Chromoting"; |
| 27 |
| 28 /** |
| 29 * Maximum dimension for the screenshot to be sent to the Send Feedback hand
ler. This size |
| 30 * ensures the size of bitmap < 1MB, which is a requirement of the handler. |
| 31 */ |
| 32 private static final int MAX_FEEDBACK_SCREENSHOT_DIMENSION = 600; |
| 33 |
| 34 private static final String FEEDBACK_PACKAGE = "com.google.android.gms"; |
| 35 |
| 36 private static final String FEEDBACK_CLASS = |
| 37 "com.google.android.gms.feedback.LegacyBugReportService"; |
| 38 |
| 39 private static final int SEND_FEEDBACK_INFO = Binder.FIRST_CALL_TRANSACTION; |
| 40 |
| 41 /** |
| 42 * Opens the feedback activity with a generated screenshot. |
| 43 * @param activity The activity for grabbing the screenshot and acting as th
e context. |
| 44 */ |
| 45 public static void sendFeedback(Activity activity) { |
| 46 View rootView = activity.getWindow().getDecorView().getRootView(); |
| 47 Bitmap screenshot = UiUtils.generateScaledScreenshot(rootView, |
| 48 MAX_FEEDBACK_SCREENSHOT_DIMENSION, |
| 49 Bitmap.Config.ARGB_8888); |
| 50 sendFeedback(activity, screenshot); |
| 51 } |
| 52 |
| 53 /** |
| 54 * Opens the feedback activity with the given screenshot image. |
| 55 * @param context The context for resource. |
| 56 * @param screenshot The screenshot image. |
| 57 */ |
| 58 public static void sendFeedback(Context context, final Bitmap screenshot) { |
| 59 Intent intent = new Intent(Intent.ACTION_BUG_REPORT); |
| 60 intent.setComponent(new ComponentName(FEEDBACK_PACKAGE, FEEDBACK_CLASS))
; |
| 61 if (context.getPackageManager().resolveService(intent, 0) == null) { |
| 62 Log.e(TAG, "Unable to resolve Feedback service."); |
| 63 return; |
| 64 } |
| 65 |
| 66 ServiceConnection conn = new ServiceConnection() { |
| 67 @Override |
| 68 public void onServiceConnected(ComponentName name, IBinder service)
{ |
| 69 try { |
| 70 Parcel parcel = Parcel.obtain(); |
| 71 if (screenshot != null) { |
| 72 screenshot.writeToParcel(parcel, 0); |
| 73 } |
| 74 service.transact(SEND_FEEDBACK_INFO, parcel, null, 0); |
| 75 parcel.recycle(); |
| 76 } catch (RemoteException ex) { |
| 77 Log.e(TAG, "Unexpected error sending feedback: ", ex); |
| 78 } |
| 79 } |
| 80 |
| 81 @Override |
| 82 public void onServiceDisconnected(ComponentName name) {} |
| 83 }; |
| 84 |
| 85 context.bindService(intent, conn, Context.BIND_AUTO_CREATE); |
| 86 } |
| 87 } |
| OLD | NEW |