Commit 8331585b authored by Tao Bai's avatar Tao Bai Committed by Commit Bot

[WebView Autofill] Always check if log is enabled

Always check if log is enabled before ouput log, this avoid
creating string object while log is disabled.

Also only check Android log property when AwAutofillManager is
created or new session starts.

Bug: 843277
Change-Id: Id2ab708646d434677d11016132cc47b6fa4985be
Reviewed-on: https://chromium-review.googlesource.com/1106959Reviewed-by: default avatarChangwan Ryu <changwan@chromium.org>
Commit-Queue: Tao Bai <michaelbai@chromium.org>
Cr-Commit-Position: refs/heads/master@{#568736}
parent 31f7bffa
...@@ -48,6 +48,7 @@ public class AwAutofillManager { ...@@ -48,6 +48,7 @@ public class AwAutofillManager {
} }
} }
private static boolean sIsLoggable;
private AutofillManager mAutofillManager; private AutofillManager mAutofillManager;
private boolean mIsAutofillInputUIShowing; private boolean mIsAutofillInputUIShowing;
private AutofillInputUIMonitor mMonitor; private AutofillInputUIMonitor mMonitor;
...@@ -56,10 +57,14 @@ public class AwAutofillManager { ...@@ -56,10 +57,14 @@ public class AwAutofillManager {
private ArrayList<WeakReference<InputUIObserver>> mInputUIObservers; private ArrayList<WeakReference<InputUIObserver>> mInputUIObservers;
public AwAutofillManager(Context context) { public AwAutofillManager(Context context) {
log("constructor"); updateLogStat();
if (isLoggable()) log("constructor");
mAutofillManager = context.getSystemService(AutofillManager.class); mAutofillManager = context.getSystemService(AutofillManager.class);
mDisabled = mAutofillManager == null || !mAutofillManager.isEnabled(); mDisabled = mAutofillManager == null || !mAutofillManager.isEnabled();
if (mDisabled) return; if (mDisabled) {
if (isLoggable()) log("disabled");
return;
}
mMonitor = new AutofillInputUIMonitor(this); mMonitor = new AutofillInputUIMonitor(this);
mAutofillManager.registerCallback(mMonitor); mAutofillManager.registerCallback(mMonitor);
...@@ -67,19 +72,19 @@ public class AwAutofillManager { ...@@ -67,19 +72,19 @@ public class AwAutofillManager {
public void notifyVirtualValueChanged(View parent, int childId, AutofillValue value) { public void notifyVirtualValueChanged(View parent, int childId, AutofillValue value) {
if (mDisabled || checkAndWarnIfDestroyed()) return; if (mDisabled || checkAndWarnIfDestroyed()) return;
log("notifyVirtualValueChanged"); if (isLoggable()) log("notifyVirtualValueChanged");
mAutofillManager.notifyValueChanged(parent, childId, value); mAutofillManager.notifyValueChanged(parent, childId, value);
} }
public void commit(int submissionSource) { public void commit(int submissionSource) {
if (mDisabled || checkAndWarnIfDestroyed()) return; if (mDisabled || checkAndWarnIfDestroyed()) return;
log("commit source:" + submissionSource); if (isLoggable()) log("commit source:" + submissionSource);
mAutofillManager.commit(); mAutofillManager.commit();
} }
public void cancel() { public void cancel() {
if (mDisabled || checkAndWarnIfDestroyed()) return; if (mDisabled || checkAndWarnIfDestroyed()) return;
log("cancel"); if (isLoggable()) log("cancel");
mAutofillManager.cancel(); mAutofillManager.cancel();
} }
...@@ -92,31 +97,31 @@ public class AwAutofillManager { ...@@ -92,31 +97,31 @@ public class AwAutofillManager {
return; return;
} }
if (checkAndWarnIfDestroyed()) return; if (checkAndWarnIfDestroyed()) return;
log("notifyVirtualViewEntered"); if (isLoggable()) log("notifyVirtualViewEntered");
mAutofillManager.notifyViewEntered(parent, childId, absBounds); mAutofillManager.notifyViewEntered(parent, childId, absBounds);
} }
public void notifyVirtualViewExited(View parent, int childId) { public void notifyVirtualViewExited(View parent, int childId) {
if (mDisabled || checkAndWarnIfDestroyed()) return; if (mDisabled || checkAndWarnIfDestroyed()) return;
log("notifyVirtualViewExited"); if (isLoggable()) log("notifyVirtualViewExited");
mAutofillManager.notifyViewExited(parent, childId); mAutofillManager.notifyViewExited(parent, childId);
} }
public void requestAutofill(View parent, int virtualId, Rect absBounds) { public void requestAutofill(View parent, int virtualId, Rect absBounds) {
if (mDisabled || checkAndWarnIfDestroyed()) return; if (mDisabled || checkAndWarnIfDestroyed()) return;
log("requestAutofill"); if (isLoggable()) log("requestAutofill");
mAutofillManager.requestAutofill(parent, virtualId, absBounds); mAutofillManager.requestAutofill(parent, virtualId, absBounds);
} }
public boolean isAutofillInputUIShowing() { public boolean isAutofillInputUIShowing() {
if (mDisabled || checkAndWarnIfDestroyed()) return false; if (mDisabled || checkAndWarnIfDestroyed()) return false;
log("isAutofillInputUIShowing: " + mIsAutofillInputUIShowing); if (isLoggable()) log("isAutofillInputUIShowing: " + mIsAutofillInputUIShowing);
return mIsAutofillInputUIShowing; return mIsAutofillInputUIShowing;
} }
public void destroy() { public void destroy() {
if (mDisabled || checkAndWarnIfDestroyed()) return; if (mDisabled || checkAndWarnIfDestroyed()) return;
log("destroy"); if (isLoggable()) log("destroy");
mAutofillManager.unregisterCallback(mMonitor); mAutofillManager.unregisterCallback(mMonitor);
mAutofillManager = null; mAutofillManager = null;
mDestroyed = true; mDestroyed = true;
...@@ -164,9 +169,25 @@ public class AwAutofillManager { ...@@ -164,9 +169,25 @@ public class AwAutofillManager {
} }
} }
public void notifyNewSessionStarted() {
updateLogStat();
if (isLoggable()) log("Session starts");
}
/**
* Always check isLoggable() before call this method.
*/
public static void log(String log) { public static void log(String log) {
// Use 'setprop log.tag.AwAutofillManager DEBUG' to enable the log at runtime.
// Log.i() instead of Log.d() is used here because log.d() is stripped out in release build. // Log.i() instead of Log.d() is used here because log.d() is stripped out in release build.
if (Log.isLoggable(TAG, Log.DEBUG)) Log.i(TAG, log); Log.i(TAG, log);
}
public static boolean isLoggable() {
return sIsLoggable;
}
private static void updateLogStat() {
// Use 'setprop log.tag.AwAutofillManager DEBUG' to enable the log at runtime.
sIsLoggable = Log.isLoggable(TAG, Log.DEBUG);
} }
} }
...@@ -255,8 +255,10 @@ public class AwAutofillProvider extends AutofillProvider { ...@@ -255,8 +255,10 @@ public class AwAutofillProvider extends AutofillProvider {
// return. // return.
if (mRequest == null) return; if (mRequest == null) return;
mRequest.fillViewStructure(structure); mRequest.fillViewStructure(structure);
AwAutofillManager.log( if (AwAutofillManager.isLoggable()) {
"onProvideAutoFillVirtualStructure fields:" + structure.getChildCount()); AwAutofillManager.log(
"onProvideAutoFillVirtualStructure fields:" + structure.getChildCount());
}
mAutofillUMA.onVirtualStructureProvided(); mAutofillUMA.onVirtualStructureProvided();
} }
...@@ -264,7 +266,9 @@ public class AwAutofillProvider extends AutofillProvider { ...@@ -264,7 +266,9 @@ public class AwAutofillProvider extends AutofillProvider {
public void autofill(final SparseArray<AutofillValue> values) { public void autofill(final SparseArray<AutofillValue> values) {
if (mNativeAutofillProvider != 0 && mRequest != null && mRequest.autofill((values))) { if (mNativeAutofillProvider != 0 && mRequest != null && mRequest.autofill((values))) {
autofill(mNativeAutofillProvider, mRequest.mFormData); autofill(mNativeAutofillProvider, mRequest.mFormData);
AwAutofillManager.log("autofill values:" + values.size()); if (AwAutofillManager.isLoggable()) {
AwAutofillManager.log("autofill values:" + values.size());
}
mAutofillUMA.onAutofill(); mAutofillUMA.onAutofill();
} }
} }
...@@ -293,6 +297,7 @@ public class AwAutofillProvider extends AutofillProvider { ...@@ -293,6 +297,7 @@ public class AwAutofillProvider extends AutofillProvider {
if (!BuildInfo.isAtLeastP()) { if (!BuildInfo.isAtLeastP()) {
mAutofillManager.cancel(); mAutofillManager.cancel();
} }
mAutofillManager.notifyNewSessionStarted();
Rect absBound = transformToWindowBounds(new RectF(x, y, x + width, y + height)); Rect absBound = transformToWindowBounds(new RectF(x, y, x + width, y + height));
mRequest = new AutofillRequest(formData, new FocusField((short) focus, absBound)); mRequest = new AutofillRequest(formData, new FocusField((short) focus, absBound));
int virtualId = mRequest.getVirtualId((short) focus); int virtualId = mRequest.getVirtualId((short) focus);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment