Wear OS

Google Pixel Watch app will crash on Honor 20 Pro with HarmonyOS 2.0.0.

Logcat

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2023-01-02 21:40:49.866 16383-16383/? E/PrivacyConsentApi: Exception while registering consent listener
equ: 17: API: Wearable.API is not available on this device. Connection failed with: epo{statusCode=API_UNAVAILABLE, resolution=null, message=null}
at erk.d(PG:1)
at ese.s(PG:7)
at ese.f(PG:2)
at ese.j(PG:21)
at ese.i(PG:1)
at androidx.wear.ambient.AmbientModeSupport$AmbientController.b(PG:1)
at etr.a(PG:1)
at etl.d(PG:6)
at etm.handleMessage(PG:38)
at android.os.Handler.dispatchMessage(Handler.java:110)
at exp.b(PG:1)
at exp.dispatchMessage(PG:1)
at android.os.Looper.loop(Looper.java:219)
at android.os.HandlerThread.run(HandlerThread.java:67)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
2023-01-02 21:03:20.439 1568-2418/? E/ActivityTaskManager: START {hwFlg=0x10 cmp=com.google.android.wearable.app.cn/com.google.android.gms.wearable.consent.TermsOfServiceActivity (has extras)} result: -92
2023-01-02 21:03:20.441 14409-14409/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.google.android.apps.wear.companion, PID: 14409
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.google.android.apps.wear.companion/com.google.android.libraries.wear.companion.invisibleactivity.impl.InvisibleActivity}: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.google.android.wearable.app.cn/com.google.android.gms.wearable.consent.TermsOfServiceActivity}; have you declared this activity in your AndroidManifest.xml?
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4060)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4247)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:91)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:149)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:103)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2613)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:219)
at android.app.ActivityThread.main(ActivityThread.java:8668)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1109)
Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.google.android.wearable.app.cn/com.google.android.gms.wearable.consent.TermsOfServiceActivity}; have you declared this activity in your AndroidManifest.xml?
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:2118)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1746)
at android.app.Activity.startActivityForResult(Activity.java:5412)
at vp.b(PG:1)
at androidx.activity.result.ActivityResultRegistry.f(PG:13)
at qz.b(PG:4)
at hwu.b(PG:1)
at jcn.a(PG:39)
at hwv.a(PG:7)
at com.google.android.libraries.wear.companion.invisibleactivity.impl.InvisibleActivity.onCreate(PG:11)
at android.app.Activity.performCreate(Activity.java:8214)
at android.app.Activity.performCreate(Activity.java:8202)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1320)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4033)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4247) 
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:91) 
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:149) 
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:103) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2613) 
at android.os.Handler.dispatchMessage(Handler.java:110) 
at android.os.Looper.loop(Looper.java:219) 
at android.app.ActivityThread.main(ActivityThread.java:8668) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1109) 

Debug

https://support.google.com/googlepixelwatch/answer/12652073?hl=en

To connect Google Pixel Watch, you need an Android phone running Android OS version 8.0 or higher.
iOS phones are not currently supported.

https://www.androidauthority.com/harmony-os-2-android-1231446/

Huawei’s HarmonyOS 2.0 may be based on Android 10.

https://support.google.com/googlepixelwatch/thread/183791114/google-pixel-watch-app-crashes-when-setting-up-device?hl=en

The pixel watch app crashes whenever I click “continue” (and also “Pair with emulator” option in the menu) on the setup page.

For more context, I’m using a Huawei P30 Pro running Harmony OS 2.0.0.268, which should be equivalent to Android 10.

https://support.google.com/wearos/answer/9266307

Watches that run Wear OS 3 are not compatible with the Wear OS app.

https://developer.android.com/training/wearables/creating-app-china

com.google.android.wearable.app.cn

Windows Env Var

Built-in envrionment variables on Windows.

https://en.wikipedia.org/wiki/Environment_variable#Windows

Variable Locale specific Windows XP (CMD) Windows Vista and later (CMD)
%ALLUSERSPROFILE% Yes C:\Documents and Settings\All Users C:\ProgramData
%APPDATA% Yes C:\Documents and Settings{username}\Application Data C:\Users{username}\AppData\Roaming
%CommonProgramFiles% Yes C:\Program Files\Common Files C:\Program Files\Common Files
%CommonProgramFiles(x86)% Yes C:\Program Files (x86)\Common Files (only in 64-bit version) C:\Program Files (x86)\Common Files (only in 64-bit version)
%CommonProgramW6432% Yes %CommonProgramW6432% (not supported, not replaced by any value) C:\Program Files\Common Files (only in 64-bit version)
%COMPUTERNAME% No {computername} {computername}
%ComSpec% No C:\Windows\System32\cmd.exe C:\Windows\System32\cmd.exe
%HOMEDRIVE% No C: C:
%HOMEPATH% Yes \Documents and Settings{username} \Users{username}
%LOCALAPPDATA% Yes %LOCALAPPDATA% (not supported, not replaced by any value) C:\Users{username}\AppData\Local
%LOGONSERVER% No \{domain_logon_server} \{domain_logon_server}
%PATH% Yes C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;{plus program paths} C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;{plus program paths}
%PATHEXT% No .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.WSF;.WSH .com;.exe;.bat;.cmd;.vbs;.vbe;.js;.jse;.wsf;.wsh;.msc
%ProgramData% Yes %ProgramData% (not supported, not replaced by any value) %SystemDrive%\ProgramData
%ProgramFiles% Yes %SystemDrive%\Program Files %SystemDrive%\Program Files
%ProgramFiles(x86)% Yes %SystemDrive%\Program Files (x86) (only in 64-bit version) %SystemDrive%\Program Files (x86) (only in 64-bit version)
%ProgramW6432% Yes %ProgramW6432% (not supported, not replaced by any value) %SystemDrive%\Program Files (only in 64-bit version)
%PROMPT% No Code for current command prompt format, usually $P$G Code for current command prompt format, usually $P$G
%PSModulePath% %PSModulePath% (not supported, not replaced by any value) %SystemRoot%\system32\WindowsPowerShell\v1.0\Modules\
%PUBLIC% Yes %PUBLIC% (not supported, not replaced by any value) %SystemDrive%\Users\Public
%SystemDrive% No C: C:
%SystemRoot% No The Windows directory, usually C:\Windows, formerly C:\WINNT %SystemDrive%\Windows
%TEMP% and %TMP% Yes %SystemDrive%\Documents and Settings{username}\Local Settings\Temp %SystemRoot%\TEMP (for system environment variables %TMP% and %TEMP%), %USERPROFILE%\AppData\Local\Temp (for user environment variables %TMP% and %TEMP%)
%USERDOMAIN% No {userdomain} {userdomain}
%USERNAME% No {username} {username}
%USERPROFILE% Yes %SystemDrive%\Documents and Settings{username} %SystemDrive%\Users{username}
%windir% No %SystemDrive%\WINDOWS %SystemDrive%\Windows

WSL Export/Import

WSL2 export and import.

1
2
3
4
5
6
7
8
9
10
PS C:\Users\songzy> wsl --list
Windows Subsystem for Linux Distributions:
Ubuntu-20.04 (Default)

PS C:\Users\songzy> wsl --export Ubuntu-20.04 D:/Ubuntu-20.04.tar

PS C:\Users\songzy> wsl --unregister Ubuntu-20.04
Unregistering...

PS C:\Users\songzy> wsl --import Ubuntu-20.04 D:/Ubuntu-20.04/ D:/Ubuntu-20.04.tar

Config Default User

Method 1:

1
2
3
4
5
Function WSL-SetDefaultUser ($distro, $user) { Get-ItemProperty Registry::HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Lxss\*\ DistributionName | Where-Object -Property DistributionName -eq $distro | Set-ItemProperty -Name DefaultUid -Value ((wsl -d $distro -u $user -e id -u) | Out-String); };

WSL-SetDefaultUser Ubuntu-20.04 songzy

Remove-Item Function:WSL-SetDefaultUser

Method 2:

1
ubuntu2004 config --default-user songzy

OMEN WSL GPU

Enable GPU on OMEN, which runs Win11 and WSL2.

https://docs.nvidia.com/cuda/wsl-user-guide/index.html

Driver

https://developer.nvidia.com/cuda/wsl

Then restart your computer.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
$ nvidia-smi

Sun Oct 24 20:28:01 2021
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 470.28 Driver Version: 470.76 CUDA Version: 11.4 |
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|===============================+======================+======================|
| 0 NVIDIA GeForce ... Off | 00000000:01:00.0 On | N/A |
| 30% 35C P8 16W / 350W | 1782MiB / 24576MiB | ERR! Default |
| | | N/A |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=============================================================================|
| No running processes found |
+-----------------------------------------------------------------------------+

NOTE: nvidia-smi only indicates highest CUDA version the installed driver supports. It does not provide any information about which CUDA version is installed or even whether there is CUDA installed at all.

Verify

1
2
cd /usr/local/cuda-11.0/samples/4_Finance/BlackScholes
./BlackScholes

Toolkit

The latest NVIDIA Windows GPU Driver will fully support WSL 2. With CUDA support in the driver, existing applications (compiled elsewhere on a Linux system for the same target GPU) can run unmodified within the WSL environment.

To compile new CUDA applications, a CUDA Toolkit for Linux x86 is needed. CUDA Toolkit support for WSL is still in preview stage as developer tools such as debugger and profilers are not available yet. However, CUDA application development is fully supported in the WSL2 environment, as a result, users should be able to compile new CUDA Linux applications with the latest CUDA Toolkit for x86 Linux.

Once a Windows NVIDIA GPU driver is installed on the system, CUDA becomes available within WSL 2. The CUDA driver installed on Windows host will be stubbed inside the WSL 2 as libcuda.so, therefore users must not install any NVIDIA GPU Linux driver within WSL 2. One has to be very careful here as the default CUDA Toolkit comes packaged with a driver, and it is easy to overwrite the WSL 2 NVIDIA driver with the default installation. We recommend developers to use a separate CUDA Toolkit for WSL 2 (Ubuntu) available here to avoid this overwriting. This WSL-Ubuntu CUDA toolkit installer will not overwrite the NVIDIA driver that was already mapped into the WSL 2 environment. To learn how to compile CUDA applications, please read the CUDA documentation for Linux.

https://developer.nvidia.com/cuda-downloads?target_os=Linux&target_arch=x86_64&Distribution=WSL-Ubuntu&target_version=2.0&target_type=deb_local

1
2
3
4
5
6
7
wget https://developer.download.nvidia.com/compute/cuda/repos/wsl-ubuntu/x86_64/cuda-wsl-ubuntu.pin
sudo mv cuda-wsl-ubuntu.pin /etc/apt/preferences.d/cuda-repository-pin-600
wget https://developer.download.nvidia.com/compute/cuda/11.7.1/local_installers/cuda-repo-wsl-ubuntu-11-7-local_11.7.1-1_amd64.deb
sudo dpkg -i cuda-repo-wsl-ubuntu-11-7-local_11.7.1-1_amd64.deb
sudo cp /var/cuda-repo-wsl-ubuntu-11-7-local/cuda-*-keyring.gpg /usr/share/keyrings/
sudo apt-get update
sudo apt-get -y install cuda

Env Var

1
2
3
export CUDA_HOME="/usr/local/cuda-11.0"
export LD_LIBRARY_PATH="/usr/local/cuda-11.0/lib64:$LD_LIBRARY_PATH"
export PATH="/usr/local/cuda-11.0/bin:$PATH"

Verify

1
nvcc -V

Reference

Appendix

Multiple CUDA Installed?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
$ which nvcc
/usr/bin/nvcc

$ nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2019 NVIDIA Corporation
Built on Sun_Jul_28_19:07:16_PDT_2019
Cuda compilation tools, release 10.1, V10.1.243

$ whereis cuda
cuda: /usr/lib/cuda /usr/include/cuda.h

$ cat /usr/lib/cuda/version.txt
CUDA Version 10.1.243

$ ls /usr/lib/cuda/bin

1
2
3
4
5
6
7
8
9
10
11
12
$ ls /usr/local | grep cuda
cuda-11.0

$ cat /usr/local/cuda-11.0/version.txt
CUDA Version 11.0.228

$ /usr/local/cuda-11.0/bin/nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2020 NVIDIA Corporation
Built on Wed_Jul_22_19:09:09_PDT_2020
Cuda compilation tools, release 11.0, V11.0.221
Build cuda_11.0_bu.TC445_37.28845127_0

WSL vDisk

WSL2 vdisk management.

WSL 2 uses a Virtual Hard Disk (VHD) to store your Linux files. In WSL 2, a VHD is represented on your Windows hard drive as a .vhdx file.
The WSL 2 VHD uses the ext4 file system. This VHD automatically resizes to meet your storage needs and has an initial maximum size of 256GB.

ncdu

1
du -h --max-depth=1 . | sort -h

or

1
2
sudo apt install ncdu
ncdu

Then press ? for shortcuts.

“ncdu” stands for “NCurses Disk Usage”, where “NCurses” stands for “new curses”, where “curses” is a pun on the term “cursor optimization”, which is a library for TUI.

detail vdisk

1
2
wsl --shutdown
diskpart
1
DISKPART> select vdisk file="C:\Users\songzy\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu20.04onWindows_79rhkp1fndgsc\LocalState\ext4.vhdx"

Windows use first 5 letters of our e-mail addresses as the name of our user account folders.

1
2
3
4
5
6
7
8
9
10
11
DISKPART> detail vdisk

Device type ID: 0 (Unknown)
Vendor ID: {00000000-0000-0000-0000-000000000000} (Unknown)
State: Added
Virtual size: 256 GB
Physical size: 141 GB
Filename: C:\Users\songz\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu20.04onWindows_79rhkp1fndgsc\LocalState\ext4.vhdx
Is Child: No
Parent Filename:
Associated disk#: Not found.

compact vdisk

1
2
3
4
5
# DISKPART> attach vdisk readonly
DISKPART> compact vdisk
# DISKPART> detach vdisk

DISKPART> exit

expand vdisk

https://docs.microsoft.com/en-us/windows/wsl/vhd-size

1
2
3
DISKPART> expand vdisk maximum=<sizeInMegaBytes>

DISKPART> exit
1
wsl.exe -l -v
1
2
3
4
sudo mount -t devtmpfs none /dev
mount | grep ext4

sudo resize2fs /dev/sdb <sizeInMegabytes>M

Windows Terminal Font

Fixing font/color issue I came across when using Windows terminals.

Powerline Fonts

https://github.com/microsoft/WSL/issues/1517

https://github.com/powerline/fonts

1
/c/Users/songzy/.local/share/fonts/ -> C:\Windows\Fonts

DejaVu Sans Mono for Powerline.

Add Fonts to Registry

This will affect what fonts are avaliable in cmd properties menu.

https://www.maketecheasier.com/add-custom-fonts-command-prompt-windows10/

1
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Console\TrueTypeFont

tmux reset font

https://github.com/microsoft/WSL/issues/3988

CodePage

https://ss64.com/nt/chcp.html

This will influence the behaviors of tmux, vim, cmd, powershell, etc.

437

  1. Open regedit.
  2. Find this. HKEY_CURRENT_USER\Console\C:_Program Files_WindowsApps_CanonicalGroupLimited.Ubuntu20.04onWindows_2004.2020.812.0_x64__79rhkp1fndgsc_ubuntu2004.exe.
  3. then, add CodePage (Type: DWORD, Value: 0x01b5).

65001

https://superuser.com/questions/269818/change-default-code-page-of-windows-console-to-utf-8

Language settings -> Administrative language settings -> Change system locale... -> Beta: Use Unicode UTF-8 for worldwide language support.

PowerShell reset font

PowerShell reset font to raster instead of using consolas as configured.

https://github.com/microsoft/terminal/issues/280

Reference

Dos Batch

Basic knowledge of dos batch.

%~dp0

  • %0: the batch file itself
  • %1-%9: command line arguments
  • d: the drive letter
  • p: the path of the parameter

cls

clean screen.

findstr

1
type *.md | findstr "<p>"

mode

Sets the number of lines and columns (characters/line) of the display.

1
mode con cols=100 lines=60

Vim

Basic usage of vim.

.vimrc

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
set ignorecase 
set hlsearch
set encoding=utf-8
set fileencodings=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936
set termencoding=utf-8
set encoding=utf-8
set cursorline
set autoindent
set smartindent
set scrolloff=4
set showmatch
set number

set tabstop=4
set softtabstop=4
set shiftwidth=4
set expandtab
set fileformat=unix

colorscheme desert

set nocompatible " required
filetype off " required

" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()

" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')

" let Vundle manage Vundle, required
Plugin 'gmarik/Vundle.vim'

" Add all your plugins here (note older versions of Vundle used Bundle instead of Plugin)
Plugin 'Chiel92/vim-autoformat'
nnoremap <F6> :Autoformat<CR>
let g:autoformat_autoindent = 0
let g:autoformat_retab = 0
let g:autoformat_remove_trailing_spaces = 0


" All of your Plugins must be added before the following line
call vundle#end() " required
filetype plugin indent on " required

vundle

https://github.com/VundleVim/Vundle.vim

1
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim 

Put this in your .vimrc.

1
Plugin 'Chiel92/vim-autoformat'

Then restart vim and run :PluginInstall.

注意这里 autoformat 要对 Python 起作用的话还要安装 autopep8:

1
pip install autopep8

syntax

1
2
cd /usr/share/vim/vim74/syntax 
vi python.vim
1
syn keyword pythonTodo      FIXME NOTE NOTES TODO XXX contained
1
2
$ ls ~/.vim/
ftdetect ftplugin indent syntax

color

1
2
3
ls /usr/share/vim/vim74/colors/
vi ~/.vimrc
color default

|

80| should get you to position 80 in that line.

d

1
2
dG 删除直到工作缓存区结尾的内容
d1G 删除直到工作缓存区开始的内容

删除第9行到第200行的内容(先用200G转到第200行) ,使用

1
:9,.d

e

重新加载

1
:e

J

合并行

In command mode:

1
[range]j[lines]

here you want to do the whole buffer:

1
%j

If you just wanted to do 10 lines from the current cursor position:

1
j10

If you dont want to replace the new lines with spaces use ! after j.

1
2
%j!
j!10

And for the uberfancy:

1
5j20

Would go to line 5, and join the next 20 lines.

ret

set tabstop=4: set the tabs to display as four spaces.
set expandtab: insert spaces for tabs.
ret: replace tab

1
2
set expandtab
:%ret! 4

s

1
:%s/源字符串/目的字符串/g

Add a string(*) to the end of each line in Vim:

1
:%s/$/\*/g

set

  • nu
1
2
set nu
set nonu
  • paste
1
set paste
  • invlist
1
2
set invlist
set nolist

shell

1
2
ctrl+z 
fg
1
:!vim --version
1
:shell

undo, redo

  • u
  • ctrl+r

vsp

1
2
3
4
vim -On file1 file2 # 分屏启动Vim
:vsp filename # 分屏
Ctrl+w r # 滚动分屏
Ctrl+w = # 分屏宽度

School Projects

A summary of what I have learnt in university.

  • 2013夏
    • 汇编
      • Bomb lab, Buf lab
      • MIPS (Microprocessor without Interlocked Pipeline Stages)
  • 2013秋(大二)
    • 程序设计与算法基础
      • 虚拟宠物
  • 2014春(大二)
    • 计算机组成与系统结构
      • Y86流水线处理器
  • 2014夏
    • 安卓
      • 计步器
  • 2014秋(大三)
    • 高等计算机图形学
      • 光线追踪
      • 网格简化
    • 机器学习
      • 广告 CTR 预测
    • 大数据算法与模型
      • Randomness Extractor
    • 编译原理
      • Decaf (Decaf is a Java-like object-oriented programming language)
  • 2015春(大三)
    • 操作系统
      • Nachos (Not Another Completely Heuristic Operating System)
      • Paxos
  • 2015夏
    • SRT
      • Topic Model
  • 2015秋(大四)
    • 软件工程
      • 安卓车载蓝牙
  • 2016秋(研一)
    • 分布式数据库系统
      • EtherLend
  • 2017春(研一)
    • 分布式系统导论
      • Raft
    • 计算几何
      • 平面最大空凸点集
    • 高级机器学习
      • 论文引用数预测
    • 计算机网络安全技术
      • Eternal Blue - Wanna Cry